Anshulupadhyay03
08/04/2021, 7:22 AMenum class Type(val value: String, val colorCode: String) {
BUY("B", GREEN),
SELL("S", RED),
UNKNOWN("", "");
private companion object {
private const val GREEN = "#3fc963"
private const val RED = "#e35353"
}
}
it is showing compile error on GREEN and RED as it should be initialized. i have init in the companion obj why is the error then?Christiano
08/04/2021, 7:30 AMType.GREEN
and Type.RED
works... đ¤Luis
08/04/2021, 7:34 AMLuis
08/04/2021, 7:34 AMLuis
08/04/2021, 7:34 AMLuis
08/04/2021, 7:34 AMBUY("B", "#3fc963"),
Anshulupadhyay03
08/04/2021, 7:51 AMAnshulupadhyay03
08/04/2021, 7:52 AMenum class Type(val value: String, val colorCode: String) {
BUY("B", Type.GREEN),
SELL("S", Type.RED),
UNKNOWN("", "");
private companion object {
private const val GREEN = "#3fc963"
private const val RED = "#e35353"
}
}
CLOVIS
08/04/2021, 8:45 AMenum class Color(val hex: String) {
RED(...)
GREEN(...)
}
enum class Type(...) {
...
}
This way you can reuse your colors in other places of your app.Luis
08/04/2021, 11:01 AMLuis
08/04/2021, 11:02 AMType
is an enum, with a fixed number of possibilities and with a fixed number of propertiesLuis
08/04/2021, 11:02 AMAnshulupadhyay03
08/04/2021, 11:49 AMappmattus
08/05/2021, 6:19 AMAnshulupadhyay03
08/05/2021, 11:32 AM