Type Parameter Constraints

This Atom is Under Construction

Type constraints allow you to impose conditions on type parameters.

Let’s revisit Enumerations. What if you’d like your enumeration to be a subtype of a trait? If this were a normal class you’d just add the trait to the list of base types during inheritance, but with enumerations you must create a new Value type by inheriting from Val. This example shows parameterized types with traits, including type constraints:

End of sample. See AtomicKotlin.com for full early-access book.

Previous          Next

©2018 Mindview LLC. All Rights Reserved.