https://kotlinlang.org logo
#android
Title
# android
k

Khan

10/29/2019, 4:02 PM
Hello. I am using Object{} which has integers which i am passing around and saving those integers in db. Does this approach have any issue? OR should i use IntDef or Enum for this purpose?
g

gildor

10/30/2019, 12:29 AM
Vote for enum
d

Derek Peirce

10/30/2019, 3:09 AM
g

gildor

10/30/2019, 3:14 AM
If you have limited amount of cases (like enum) why do you need inline class? Inline class make sense if you want to have special type for ids and other primitive/string types Tho I just not sure that described case related to inline classes
k

Khan

10/30/2019, 9:03 AM
Thanks for the recommendation. I have only 3 or 4 cases. Which are 0..4. so i am setting value to each enum and using it.
z

zhuinden

10/31/2019, 1:01 PM
Object[]
why?
k

Khan

10/31/2019, 1:04 PM
Untitled
z

zhuinden

10/31/2019, 1:04 PM
that's... what enums are for 🤔 (
enum class
) and then you can do
= when(enumValue) {
k

Khan

10/31/2019, 1:06 PM
Exactly now i have changed it to enum Something like this:
👍 2
g

gildor

10/31/2019, 3:23 PM
I wouldn't use value for this. Or use ordinal, or serialize it as name of enum
k

Khan

10/31/2019, 3:27 PM
I understand ordinal thing. But can you please add an example why would you serialize name?
g

gildor

10/31/2019, 3:58 PM
Easier to support backward compatibility (you can add and delete items), easier to debug DB records