Generics Flashcards
What is Type erasure?
Process of converting generics to Objects
Static and generics?
Not permitted. static T
Primitives and generics?
Not permitted. < int >
Instantiating a generic?
Not permitted. new T()
Checking instanceof a generic?
Not permitted.
Using generic in ArrayList?
Not permitted. new ArrayList< T >
What generics actually become after compile?
Object
What types of wildcard generics do we have?
Unbounded, upper bounded, lower bounded
What are unbound generics?
<?>
Can we pass multiple generics?
Yes. <T, U>
Can wildcard generics be used as return types?
No
Where do we use wildcard generics?
Mostly as parameters or as local variable types
Why would we use wildcard generics?
To define code that can be more universal
At what level are generics resolved?
At instance level
Why cannot we use generics with static?
Because static is resolved at class level, not instance level like generics