We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
const
@JvmField
class Constants { companion object { // won't compile const val FOO = Foo() } }
@JvmFields
class Constants { companion object { @JvmField val FOO = Foo() } }
Let's take the following code:
fun main(args: Array<String>) { println(Constants.FOO) }
Here's what we get with @JvmField val FOO = Foo():
@JvmField val FOO = Foo():
public final class MainKt { public static final void main(@NotNull String[] args) { Intrinsics.checkParameterIsNotNull(args, "args"); Foo var1 = Constants.FOO; System.out.println(var1); } }
And with const val FOO = "foo":
const val FOO = "foo":
public final class MainKt { public static final void main(@NotNull String[] args) { Intrinsics.checkParameterIsNotNull(args, "args"); String var1 = "foo"; System.out.println(var1); } }
There's no call to Constants.FOO in the second example, the value has been inlined.
Constants.FOO
The text was updated successfully, but these errors were encountered:
No branches or pull requests
const
it only works with primitives and Strings:const
val get inlined by the compiler, while@JvmFields
don'tLet's take the following code:
Here's what we get with
@JvmField val FOO = Foo():
And with
const val FOO = "foo":
There's no call to
Constants.FOO
in the second example, the value has been inlined.The text was updated successfully, but these errors were encountered: