GENERICS (Java)

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

1/37

encourage image

There's no tags or description

Looks like no tags are added yet.

38 Terms

1
New cards
Generics
A feature in Java that allows code to work with different data types using a single implementation
2
New cards
Generic type
A class or interface that is parameterized with one or more type parameters
3
New cards
Type parameter
A placeholder for a data type specified within angle brackets
4
New cards
T
A common type parameter name representing a generic type
5
New cards
E
A type parameter commonly used to represent an element
6
New cards
K
A type parameter commonly used to represent a key
7
New cards
V
A type parameter commonly used to represent a value
8
New cards
N
A type parameter commonly used to represent a number
9
New cards
Parameterized type
A class that uses type parameters to handle different data types
10
New cards
Angle brackets
Symbols (< >) used to declare type parameters in generics
11
New cards
Generic class
A class that uses a type parameter to define its data type
12
New cards
Gen<T>
An example of a generic class where T is a placeholder type
13
New cards
setValue(T dt)
A method that assigns a value of type T to a variable
14
New cards
getValue()
A method that returns a value of type T
15
New cards
showType()
A method that displays the actual data type of the generic parameter
16
New cards
getClass()
A method that returns the runtime class of an object
17
New cards
getName()
A method that returns the name of a class as a string
18
New cards
Generic object initialization
The process of creating an object with a specific type for a generic class
19
New cards
Gen<Integer>
An example of a generic object using Integer as the type parameter
20
New cards
Gen<String>
An example of a generic object using String as the type parameter
21
New cards
Diamond operator
The use of <> on the right side of object creation where type is inferred
22
New cards
Multiple type parameters
Using more than one type parameter in a generic class such as <T
23
New cards
Gen<T
T2>
24
New cards
Wildcard
A symbol (?) used to represent an unknown type in generics
25
New cards
Unbounded wildcard
A wildcard (?) that accepts any type
26
New cards
List<?>
A list that can contain elements of any type
27
New cards
Upper-bounded wildcard
A wildcard that restricts the type to a specific class or its subclasses
28
New cards
An example that allows Number and its subclasses like Integer or Double
29
New cards
Lower-bounded wildcard
A wildcard that restricts the type to a specific class or its superclasses
30
New cards
An example that allows Integer and its superclasses like Number or Object
31
New cards
printList(List<?> list)
A method that can accept a list of any data type
32
New cards
sumOfList(List<? extends Number>)
A method that works only with numeric types and their subclasses
33
New cards
addNumbers(List<? super Integer>)
A method that adds integers to lists that accept Integer or its superclasses
34
New cards
Type safety
A feature of generics that ensures only the correct data type is used
35
New cards
Code reusability
The ability to use the same code for different data types
36
New cards
Compile-time checking
Error checking done during compilation to ensure type correctness
37
New cards
Class object
A representation of a class at runtime returned by getClass()
38
New cards
Generic flexibility
The ability of generics to adapt to different data types without rewriting code