-
Notifications
You must be signed in to change notification settings - Fork 0
Traits
Sxtanna edited this page Jul 8, 2020
·
2 revisions
trait 'name'{(property declarations)} {
(property and function declarations)
}
trait
- All traits start with the
trait
keyword.
- name
- Trait names must follow
UpperCamelCase
naming standards.
- property declarations
- Traits support shorthand declaration of properties.
- property and function declarations
- Traits support declaring the signature of properties and functions.
trait Person {
val name: Txt
val age: Int
}
// or in shorthand
trait Person(val name: Txt, val age: Int)
trait with functions
trait Array {
fun get(index: Int): All
fun set(index: Int, value: All)
}