Created
June 19, 2020 00:42
-
-
Save sagarpatel288/6e0e5a5b8edb31591b7212bd6993d942 to your computer and use it in GitHub Desktop.
Showing how to access kotlin top-level members from Java
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/18/2020 | |
* Accessing java {@code public static final} like kotlin top-level members. | |
* We can access top-level members even those without having {@code @JvmField} annotation. | |
* | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
private void accessVal() { | |
/* | |
* 6/19/2020 | |
* [topLevelVal] is defined at top-level as: | |
* ``` | |
* val topLevelVal = "top-level val" | |
* ``` | |
* | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
String topLevelVal = FinalValInClassKt.getTopLevelVal(); | |
/* | |
* 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 | |
*/ | |
String constValOutsideClass = FinalValInClassKt.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 | |
*/ | |
String jvmFieldValOutsideClass = FinalValInClassKt.jvmFieldValOutsideClass; | |
/* | |
* 6/19/2020 | |
* [topLevelFun] is defined at top-level as: | |
* ``` | |
* fun topLevelFun() = "top-level function" | |
* ``` | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
String topLevelFun = FinalValInClassKt.topLevelFun(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment