Skip to content
Sxtanna edited this page Jul 8, 2020 · 2 revisions

Traits are special "skeleton" type definitions, they can define required properties and functions

Syntax

trait 'name'{(property declarations)} {
  (property and function declarations)
}

  1. trait
  • All traits start with the trait keyword.
  1. name
  • Trait names must follow UpperCamelCase naming standards.
  1. property declarations
  • Traits support shorthand declaration of properties.
  1. property and function declarations
  • Traits support declaring the signature of properties and functions.

Examples

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)
}