Richard Cumberland
03/08/2019, 12:09 PMtry/catch?
val port: Int = when (val p = System.getenv().getOrDefault("PORT","8080").toInt()) {
is Int -> p
else -> 8080
}diesieben07
03/08/2019, 12:13 PMtoInt will throw if it can't parse it so you will just get an uncaught exception. You can only catch exceptions using try-catch. If you want to use "pattern matching", you have to use toIntOrNull, which will return null in case of an unparseable value:
val port = System.getenv().getOrDefault("PORT", "8080").toIntOrNull() ?: 8080Richard Cumberland
03/08/2019, 12:13 PMelse case would catch an exception, and i guess it doesn't!Richard Cumberland
03/08/2019, 12:14 PMval p = part of that and still use the value?Richard Cumberland
03/08/2019, 12:14 PMdiesieben07
03/08/2019, 12:15 PMval p = syntax is fordiesieben07
03/08/2019, 12:15 PMwhen here is way overkill anyways.Richard Cumberland
03/08/2019, 12:16 PMRichard Cumberland
03/08/2019, 12:16 PMdiesieben07
03/08/2019, 12:16 PMdiesieben07
03/08/2019, 12:16 PMRichard Cumberland
03/08/2019, 12:16 PMRichard Cumberland
03/08/2019, 12:16 PMsitepodmatt
03/08/2019, 12:45 PMsitepodmatt
03/08/2019, 12:49 PM