Skip to main content
8 of 12
deleted 1 character in body
Gastón Saillén
  • 13.3k
  • 5
  • 75
  • 82

Use a companion object to enclose a static method / variable

class Foo{ companion object { fun sayFoo() = println("Foo") val bar ="bar" } } 

2. Usage:

Foo.sayFoo() // Output Foo println(Foo.bar) . // Output Bar 
erluxman
  • 19.6k
  • 22
  • 101
  • 129