~/ learn/ comp-308/ cards/ Generics
1 of 19

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/e7932c93-b1e8-4e8f-8704-ad687296b92b/flashcard utf-8 LF