~/ 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/0a5466aa-0ea7-4554-abc8-2a224f53cbfb/flashcard utf-8 LF