Skip to content

Instantly share code, notes, and snippets.

@davinctor
Created March 31, 2017 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davinctor/5340a0a5fcd5d800b2a88b484e759ba8 to your computer and use it in GitHub Desktop.
Save davinctor/5340a0a5fcd5d800b2a88b484e759ba8 to your computer and use it in GitHub Desktop.
Inner enum
public enum UpdateMode {
UPDATE_SIMPLE_MODE(ConnectivityMode.WIFI, ConnectivityMode.ETHERNET),
UPDATE_FAST_MODE(ConnectivityMode.ETHERNET)
}
public enum ConnectivityMode {
WIFI,
ETHERNET
}
// and then somewhere in code
switch (mUpdateMode.mConnectivityMode) {
case ConnectivityMode.WIFI:
// update simple via wifi
break;
case ConnectivityMode.ETHERNET:
// update simple via ehternet
break;
}
@davinctor
Copy link
Author

How to make it in Kotlin:

enum class Big(vararg val small: Small) {
    A(Small.A, Small.B), B(Small.B)
}
enum class Small {
    A, B
}

fun example() {
    val big = Big.A
    when {
        Small.A in big.small -> println("A")
        Small.B in big.small -> println("B")
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment