Java Generics Flashcards

1
Q

Why use java generics

A

To avoid rewriting code to be used for lots of different types

Instead write one which will have a generic type that can be implemented for all types

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

between what symbols should the type be put in between

A

< >

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

what is a primitive type in java

A

the predefined data types eg int, string, long, float, boolean

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

what is a wrapper in java

A

a way to use the primitive types as objects

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

what is the Int wrapper class

A

Integer

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

What happens if a client modifies the data structure while iterating?

A

A fail-fast iterator throws a java.util.ConcurrentModificationException.

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

when a class is initialised what will the placeholder be replaced with

A

the actual type

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

what is the issue with the operation

object 1 == object 2

A

will only compare the memory addresses, but most of the time, we do not want to know this

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

What does the comparable interface return if the objects are the same

A

0

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