Hi....how to create below equivalent in kotlin ...
# getting-started
g
Hi....how to create below equivalent in kotlin public final class Constants { public static final String TWO_PANE_KEY = "is_two_pane"; private Constants() { } public static class DetailActivityKeys { public static final String STORY_URL_KEY = "storyURL"; public static final String IMAGE_URL_KEY = "imageURL"; public static final String SUMMARY_KEY = "summary"; public static final String TITLE_KEY = "title"; } public static class API { public static final String BASE_URL = "https://api.myjson.com/"; } } I know I can make on companion class to hold all constants .....but how to group constants in inner classes
a
gauravm: can you give us your kotlin code and what does not work with it?
g
class Constants { companion object { val TWO_PANE_KEY = "is_two_pane" val STORY_URL_KEY = "storyURL" val IMAGE_URL_KEY = "imageURL" val SUMMARY_KEY = "summary" val TITLE_KEY = "title" val BASE_URL = "https://api.myjson.com/" } }
In kotlin i have to make one companion class....but how to make multiple inner static class like behaviour
so that each class has its realted constants
a
you can try class{class{companion}, class{companion}}
g
ahh ok thanks
i
If you need not instantiate those inner static classes, you can make them nested `object`s in kotlin