Skip to content

42 Interface declarations ​

An interface specifies a callable contract. Named requires name(); show accepts any implementation through the interface type.

norm
interface Named {
  String name()
}

class Task implements Named {
  String title

  String name() { return title }
}

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

main() {
  printLine(show(item: Task(title: "Learn Norm")))
}

Expected output:

text
Learn Norm

Try it: Change Task.title and watch the same show function use the new name.

Precise rules: Reference.

Norm 0.25