Java Medium · Lesson 1 · On the house

Generics deeper

Bounds and wildcards. Lesson 1 is free — on the house.

Lessons · Java Medium · Lesson 1 of 10 · On the house

Generics deeper

Bounds and wildcards.

Illustration for the Java course
Lesson 1 is on the house. The rest opens with the paper, the Daily, or a gift.

I am the Host. This is Java · medium, lesson 1: Generics deeper. Read the teaching and the stills before the checks. The quizzes are open book and test the subject — Java itself — not product rules or layout trivia.

You already know Introductory and Easy. Medium assumes those habits and asks for sharper tools.

bounds T.

? extends / ? super wildcards.

PECS: producer extends, consumer super.

Avoid raw types.

Put Generics deeper in a sentence you could teach a friend: what changes, what stays the same, and what you expect from the still.

Change one dial at a time when you experiment, then re-run. Batch changes invent ghost bugs.

Predict the still on paper before you type. Prediction turns running into confirmation.

Name each token in the still aloud. Hesitation marks the exact gap.

When something fails, read the last error line first. Calm retries beat rewriting everything.

Open-book means the page is a tool. Pick the claim that matches what we traced.

Keep mistaken traces beside corrected ones. The diff is the real lesson.

Label the runtime or toolchain you are using. Boring mismatches still burn evenings.

gen

import java.util.*;
public class G {
  static double sum(List<? extends Number> xs) {
    double t = 0;
    for (Number n : xs) t += n.doubleValue();
    return t;
  }
  public static void main(String[] args) {
    System.out.println(sum(List.of(1, 2)));
  }
}
Match this when you type. Open book.

Sit with that still. Trace it top to bottom. Name each piece. The exercise asks you to match its essence.

If something fails when you try it yourself, change one thing. Read the error. Return to the still. I will not rush you.

Quiz

T extends Number bounds?

Quiz

PECS means?

Quiz

Avoid?

Quiz

sum of 1,2?

Quiz

Based on today's teaching, which claim is right?

Quiz

Based on today's teaching, which claim is right?

Quiz

Based on today's teaching, which claim is right?

Quiz

Based on today's teaching, which claim is right?

Quiz

Based on today's teaching, which claim is right?

Quiz

Based on today's teaching, which claim is right?

Check

Match the still for: Generics deeper.

That is the lesson. When every quiz and exercise on this page is green, mark it passed. Next lesson when you are ready.

Open-book: the answers are on this page. Pass every quiz and check (11) to mark the lesson done. This visit: 0/11.

Generics deeper · Java Medium (free) — The Gold Standard