Static Class in Kotlin

Earlier this week I need to create a static class in Kotlin. If you are coming from Java like myself, the syntax is slightly different, but still easy. Here’s the code

class Constants { 
  companion object {
    val constantKey = "KeyValue"    
    fun getConstant() : String { return "KeyValueFromFun" }
  } 
}

You can then use the class like this:

Constants.constantKey
Constants.getConstant()