https://kotlinlang.org logo
#announcements
Title
# announcements
a

am414

07/05/2019, 2:34 PM
any help plz if I have many Constantsvalues in a class inside Companion object function and I don't wanna the imports be like this
Copy code
import com.john.movie.util.Constants.Companion.NOW_PLAYING_MOVIES
import com.john.movie.util.Constants.Companion.POPULAR_MOVIES
import com.john.movie.util.Constants.Companion.TOP_RATED_MOVIES
import com.john.movie.util.Constants.Companion.UP_COMING_MOVIES
this not working
import com.john.movie.util.Constants.Companion.*
k

karelpeeters

07/05/2019, 2:40 PM
Why did you post that in #android? Pick one (preferably correct) channel and post it there.
👍 2
I don't think there's another way to do this though.
👍 1
a

am414

07/05/2019, 2:48 PM
@karelpeeters thanks
k

karelpeeters

07/05/2019, 2:49 PM
Can I ask why you're worried about the length of the imports?
👍 1
a

am414

07/05/2019, 2:52 PM
@karelpeeters yeah, it's around 40 Constant value in that class so then I will call it in many places on my app so this may be boilerplate code or something bad i think 😏
k

karelpeeters

07/05/2019, 2:53 PM
Are there are 40 of them, then it starts to make sense. Could you make them an enum? Or maybe the code somehow so it doesn't need to refer to specific values everywhere?
👍 1
a

am414

07/05/2019, 3:00 PM
@karelpeeters mmmm I know enums but I never used it before 😂 so actually I don't know it will be a proper solution or not I just have around 40 Constant values some of them are an integer like id from 1 to 20 (maybe I can add those values inside enum mmmm) the rest is just string
k

karelpeeters

07/05/2019, 3:03 PM
Yeah definitely replace loose integer ids with enums.
💯 1
🙏 1
👌 2
a

am414

07/05/2019, 3:08 PM
thanks a lot, @karelpeeters for your help
2 Views