hi, is there a way to override the valueOf functio...
# announcements
h
hi, is there a way to override the valueOf function for enums in kotlin?
g
No, you cannot do that.
h
aw 😞
g
Create a new builder function
h
wdym?
g
fun String.toSomeEnum():
Copy code
SomeEnum {
  // My custom code that maps string to enum
}
h
ah, i can’t do that. i am using APACHE’s CSV lib, and you can assign columns to enums, but the columns have under scores and i want to keep the convention
g
You need some layer of abstraction for that
or just rename enum
h
rename enum?
g
SomeEnum -> SOME_ENUM
h
oh, using typealias?
g
no, you cannot use typealias for that
typealias doesn’t exist on runtime
h
can you explain what you mean? I’m not sure what you mean by rename enum, sorry
g
just change name of enum to match column name
h
oh, i dont wanna do that though :p[
cuz the collumn names are like
STUDENT_NAME
g
and it’s actually name convention for enums
h
oh really?
okay
g
For enum constants, it’s OK to use either uppercase underscore-separated names (enum class Color { RED, GREEN }) or regular camel-humps names starting with an uppercase letter, depending on the usage.
h
oh, cool