Java Generics Syntax

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/3

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 11:53 PM on 6/1/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

4 Terms

1
New cards

Define a generic class with one field, a constructor and get/set methods. Give examples of Instantiating the class with String and Integer types.

class Box<T> {
    private T value;

    Box(T value) { this.value = value; }

    T get() { return value; }

    void set(T value) { this.value = value; }
}

Box<String> nameBox = new Box<>("Alice");
String name = nameBox.get();

Box<Integer> numberBox = new Box<>(42);
Integer number = numberBox.get();

2
New cards

Define a generic class with more than one type parameter. Define the fields, a constructor and get methods for the class. Give examples of instantiating the class with String and Integer types.

3
New cards

Define two generic records, one with one type parameter and one with two type parameters. Give examples of instantiating the record with String and Integer types.

4
New cards

Define three generic interfaces, one with one type parameter and another with two type parameters. Give an example of the interface being implemented with concrete types.