Chapter 19: Generic Classes Flashcards

1
Q

What is a generic class?

A

A generic class is a class with one or more type arguments written in <>. When an instance is made, types are supplied

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a bound type parameter?

A

A type parameter can be a bound type. They specify what types of arguments are allowed e.g. extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where can’t type parameters be used?

A

We cannot refer to type parameters in any static parts i.e. class variables or class methods

We cannot create instances of a type parameter not arrays with array elements of that type. Compiler has to be able to perform type checking at compile time and virtual machine has no knowledge of type parameters so cannot create instances of them

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is raw type?

A
A generic class is still a class and hence a type. We can create instances without supplying type arguments, which is the raw type.
When we use raw types, the compile assumes best known type for each parameter but gives unchecked warnings.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Describe Integer as a box for int

A

Integer can be used to warp up int values as objects. It boxes it. intValue() retrieves an int

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe autoboxing

A

int and Integer can be automatically boxed and unboxed by the compiler. They work seamlessly together

How well did you know this?
1
Not at all
2
3
4
5
Perfectly