https://kotlinlang.org logo
Title
h

halirutan

08/30/2017, 10:42 PM
Here is a beginners question. In java one sometimes uses
interface
to hold data-values
public interface SymbolNames {
  String BeginPackage = "BeginPackage";
  String EndPackage = "EndPackage";
  String End = "End";
}
What is the equivalent in Kotlin? When I convert the above to Kotlin it gives me an interface with a companion object. Is this the way to go?
k

karelpeeters

08/30/2017, 10:44 PM
Either that or top-level values, yes. Or maybe this can actually be an enum?
h

halirutan

08/30/2017, 11:11 PM
Thanks! And top-level values mean basically just putting them inside the file like
const val BeginPackage = "BeginPackage"
const val EndPackage = "EndPackage"
const val End = "End"
An enum doesn't really fits as it's really only a collection of similar things but not enumerable.
k

karelpeeters

08/31/2017, 6:43 AM
Yup that's what I meant.
A singleton might work too actually:
object SymbolNames {
    ...
}
h

halirutan

09/01/2017, 2:44 AM
@karelpeeters Yes, a singelton is what I used in the end. Thanks again.