Tutorial by Examples

object CommonUtils { var anyname: String ="Hello" fun dispMsg(message: String) { println(message) } } From any other class, just invoke the variable and functions in this way: CommonUtils.anyname CommonUtils.dispMsg("like static call")
Kotlin objects are actually just singletons. Its primary advantage is that you don't have to use SomeSingleton.INSTANCE to get the instance of the singleton. In java your singleton looks like this: public enum SharedRegistry { INSTANCE; public void register(String key, Object thing) {} ...

Page 1 of 1