https://kotlinlang.org logo
Title
g

gauravm8

04/29/2017, 5:31 PM
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

Andreas Sinz

04/29/2017, 5:36 PM
gauravm: can you give us your kotlin code and what does not work with it?
g

gauravm8

04/29/2017, 5:38 PM
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

anton.golovin

04/29/2017, 5:52 PM
you can try class{class{companion}, class{companion}}
g

gauravm8

04/29/2017, 5:52 PM
ahh ok thanks
i

ilya.gorbunov

04/29/2017, 10:27 PM
If you need not instantiate those inner static classes, you can make them nested `object`s in kotlin