Created
June 24, 2020 05:48
-
-
Save sagarpatel288/9fc94ed0ccd86fc3ef3c6dc6dedda2a1 to your computer and use it in GitHub Desktop.
Showing access to a kotlin "public final" class from outside the class
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/23/2020 | |
* Examining access to a `public final` class for `var` from outside the class. | |
* | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
fun main() { | |
/** | |
* 6/23/2020 | |
* An object of a [VarInClass] showing access to a `public final` class. | |
* | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
val varInClass = VarInClass() | |
/** | |
* 6/24/2020 | |
* "varInClassCompileTime" is defined in the "public final" kotlin class as: | |
* ``` | |
* var varInClassCompileTime = "var in class for known value at compile time" | |
* ``` | |
* prints: "var in class for known value at compile time" | |
* | |
* @since 1.0 | |
*/ | |
println(varInClass.varInClassCompileTime) | |
/** | |
* 6/24/2020 | |
* We are accessing the kotlin "var" variable defined | |
* in a kotlin "public final" class as: | |
* ``` | |
* var varInClassRunTime = someFun() | |
* ``` | |
* prints (unknown result of the function "someFun()"): runtime value from the function | |
* | |
* @since 1.0 | |
*/ | |
println(varInClass.varInClassRunTime) | |
/** | |
* 6/24/2020 | |
* We are accessing the kotlin "var" variable defined | |
* in a kotlin "public final" class as: | |
* ``` | |
* @JvmField | |
* var jvmFieldVarInClass = someFun() | |
* ``` | |
* prints (unknown result of the function "someFun()"): runtime value from the function | |
* | |
* @since 1.0 | |
*/ | |
println(varInClass.jvmFieldVarInClass) | |
/*println(varInClass.varInClassPrivate)*/ //we cannot access "private" members | |
/** | |
* 6/24/2020 | |
* We are accessing the kotlin "public" function defined in a kotlin "public final" class as: | |
* ``` | |
* fun publicFun() = "public fun" | |
* ``` | |
* prints (unknown result of the function "publicFun()"): public fun | |
* | |
* @since 1.0 | |
*/ | |
println(varInClass.publicFun()) | |
/*println(varInClass.someFun())*/ //We cannot access "private" functions. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment