Last active
April 2, 2023 10:10
-
-
Save dacr/04b3aa4c8c47d13330fdd8ea918d71c5 to your computer and use it in GitHub Desktop.
scala3 feature examples - explicit nulls / published by https://github.com/dacr/code-examples-manager #d63219ff-c8cf-46f3-a927-d311db37ab35/dbc7531b140f994b388d4449b8fc56c1844030b3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : scala3 feature examples - explicit nulls | |
// keywords : scala3, tutorial | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : d63219ff-c8cf-46f3-a927-d311db37ab35 | |
// created-on : 2021-04-21T11:45:13+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
//// run-with : scala-cli --scalac-option -Yexplicit-nulls $file | |
//> using scala "3.1.1" | |
// using options -Yexplicit-nulls | |
@main def go():Unit = { | |
val nullableResult : String | Null = java.lang.System.getenv("PATH") | |
if (nullableResult != null) { | |
val result: String = nullableResult // safe because of the previous test :) | |
println(result) | |
} | |
val aresult:String = nullableResult // FAIL when the explicit feature is enabled (-Yexplicit-nulls) | |
println(aresult) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment