Mindmap
Generics
Inhalt der Mindmap
Generics
Generics
- Type parameter: placeholder for a type declared in a generic
- Type argument: actual type used to parametrize a generic
Generic Constrainst
- Type parameter bound: limit possible values of type argument. We need to explicity define a type parameter upper bound
- Nullabilty: non-nullable and nulable types as type argument. We need to explicity define a non-nullable type explicity
Variance
- Modifiers
- Covariant: subtyping is preserved
- out
- Contravarient: reversed
- in
- Invariant: ignored. Default
- Covariant: subtyping is preserved
- Place in the code
- use-site
- declaration-site
- Collection
- Invariant by default
- List: co-variant
- MutableList: invariant
- Limitation: only limited to a single position
- in: method parameters
- out: method return value
- Constructor
- parameters are always invariant
- Modifiers
Type erasure
- Process of removing a type argument from a generic type
- JvmName to change the name of one of the methods
- Reified
- special modier that can preserve a type-argument at runtime
- only with inline functions
- Process of removing a type argument from a generic type
Star-projections
- way to say that information about type argument is missing or it is not important
programming style where classes, fuctions, data structures or algorithms are written in such way that the exact type can be specified late
Informationen
- Beschreibung
- Mindmap am Generics, erstellt von Jose Juan Ramírez am 12/01/2018.
- Erstellt von
- Jose Juan Ramírez
- Aufrufe
- 0
- Bewertung