Sobes.tech
Junior — Middle

How can you access a static variable defined in Java from Kotlin?

sobes.tech AI

Answer from AI

In Kotlin, to access static variables of Java, the class name is used directly, since Kotlin does not have its own concept of static, but it compiles to JVM and can access static members of Java classes.

For example, if there is a Java class:

public class Constants {
    public static final String API_KEY = "12345";
}

In Kotlin, you can access it like:

val key = Constants.API_KEY

That is, just through the class name and variable name, as in Java.