Last active
June 17, 2020 00:25
-
-
Save sagarpatel288/7baf5651f97b0a105df49d908265307f to your computer and use it in GitHub Desktop.
Java static like variable in kotlin
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/15/2020 | |
* An example of java `static` like variable in kotlin | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
object StaticInObjectDeclaration { | |
/** | |
* 6/15/2020 | |
* By default, it is private and Unable to reach from Java! | |
* Check below, 2nd example, [jvmStaticExample] to expose a field to Java caller. | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
var staticExample = "staticExample" | |
/** | |
* 6/15/2020 | |
* `@JvmField` to expose a field to Java callers. Available from Java! | |
* Use `@JvmStatic` to expose a static method to Java callers. | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
@JvmField var jvmStaticExample = "jvmStaticExample" | |
/** | |
* 6/15/2020 | |
* ```@JvmField``` to expose a field to Java callers. Available from Java! | |
* Use ```@JvmStatic``` to expose a static method to Java callers. | |
* @author srdpatel | |
* @since 1.0 | |
*/ | |
@JvmStatic | |
fun jvmStaticMethod() = "jvmStaticMethod" | |
fun staticMethod() = "staticMethod" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment