~/ learn/ comp-308/ cards/ Why generics & generic classes
1 of 4

Type the generic class header and fields

Type the generic class header and fields

Answer

public class TwoTuple<A, B> { public final A first; public final B second; }

A and B are type parameters declared after the class name. Inside the class they act as types for the fields. Each object instantiated with concrete arguments (e.g. TwoTuple<String, Integer>) binds A and B to those types.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f18ed4fa-9592-4f37-9968-d0069ddd3033/flashcard utf-8 LF