Last active
June 19, 2020 00:33
-
-
Save sagarpatel288/5a1911e9a86733ed5e960b893b435756 to your computer and use it in GitHub Desktop.
Showing how to call (access) kotlin top-level "val", "const val" and "@JvmField val" members
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
/** | |
* 6/16/2020 | |
* Accessing java static like members defined inside of an object declaration and a companion object. | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
fun main() { | |
//region Accessing top-level members | |
/** | |
* 6/19/2020 | |
* [topLevelVal] is defined at top-level as: | |
* ``` | |
* val topLevelVal = "top-level val" | |
* ``` | |
* | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
println(topLevelVal) | |
/** | |
* 6/19/2020 | |
* [constValOutsideClass] is defined at top-level as: | |
* ``` | |
* const val constValOutsideClass = "a const val outside the class at top-level" | |
* ``` | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
println(constValOutsideClass) | |
/** | |
* 6/19/2020 | |
* [jvmFieldValOutsideClass] is defined at top-level as: | |
* ``` | |
* @JvmField | |
* val jvmFieldValOutsideClass = "jvmField val outside the class at top-level" | |
* ``` | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
println(jvmFieldValOutsideClass) | |
/** | |
* 6/19/2020 | |
* [topLevelFun] is defined at top-level as: | |
* ``` | |
* fun topLevelFun() = "top-level function" | |
* ``` | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
println(topLevelFun()) | |
//endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment