Generics Flashcards

1
Q

Advantage of generics?

A

No casting. Avoid runtime errors by encouraging compile time errors.

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

Write basic generic class.

A

public class Box{}

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

What are types in Java?

A

Classes and interfaces.

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

What is generics?

A

Generics enables classes and interfaces to be parameters when defining classes, interfaces and methods. Called Type Parameters.

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

Give example of generics:

A

public interface List {}

static void arrayToList(T[] a, List c) { …}

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