August 2017
Intermediate to advanced
440 pages
10h
English
When we define a class with an unbounded type parameter, we can use both non-nullable and nullable types as type arguments. Occasionally, we need to make sure that a particular generic type will not be parametrized with nullable type arguments. To block the ability to use nullable types as type arguments, we need to explicitly define a non-nullable type parameter upper bound:
class Action (val name:String) class ActionGroup<T : Action> // non-nullable type parameter upper bound var actionGroupA: ActionGroup<Action> var actionGroupB: ActionGroup<Action?> // Error
Now we can't pass a nullable type argument (Action?) to the ActionGroup class.
Let's consider another example. Imagine that we want to retrieve the last Action in
Read now
Unlock full access