~/ 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/d0b6d2d3-bbfa-469d-94d8-2496fdc76d9c/flashcard utf-8 LF