Skip to content

43 Implementing an interface ​

implements Named promises a matching name() method. A value can satisfy the contract as well as a class; the caller depends only on Named.

norm
interface Named {
  String name()
}

value TaskId implements Named {
  Integer number

  String name() { return "task-${number}" }
}

String show(Named item) { return item.name() }

main() {
  TaskId id = TaskId(number: 7)
  printLine(show(item: id))
}

Expected output:

text
task-7

Try it: Remove name() and inspect the compiler error.

Precise rules: Reference.

Norm 0.25