Package kotlin.jvm

Functions and annotations specific to the Java platform.

Types

JVM
JRE8
1.6

JvmRepeatable

Makes the annotation class repeatable in Java and Kotlin. A repeatable annotation can be applied more than once on the same element.

typealias JvmRepeatable = Repeatable

Annotations

Common
JVM
1.9

ImplicitlyActualizedByJvmDeclaration

This annotation marks Kotlin expect declarations that are implicitly actualized by Java.

annotation class ImplicitlyActualizedByJvmDeclaration
JVM
1.2

JvmDefault

Specifies that a JVM default method should be generated for non-abstract Kotlin interface member.

annotation class JvmDefault
JVM
1.6

JvmDefaultWithCompatibility

Forces the compiler to generate compatibility accessors for the annotated interface in the DefaultImpls class. Please note that if an interface is annotated with this annotation for binary compatibility, public derived Kotlin interfaces should also be annotated with it, because their DefaultImpls methods will be used to access implementations from the DefaultImpls class of the original interface.

annotation class JvmDefaultWithCompatibility
JVM
1.4

JvmDefaultWithoutCompatibility

Prevents the compiler from generating compatibility accessors for the annotated class or interface, and suppresses any related compatibility warnings. In other words, this annotation makes the compiler generate the annotated class or interface in the -Xjvm-default=all mode, where only JVM default methods are generated, without DefaultImpls.

annotation class JvmDefaultWithoutCompatibility
Common
JVM
1.0

JvmField

Instructs the Kotlin compiler not to generate getters/setters for this property and expose it as a field.

annotation class JvmField
Common
JVM
1.5

JvmInline

Specifies that given value class is inline class.

annotation class JvmInline
Common
JVM
1.0

JvmMultifileClass

Instructs the Kotlin compiler to generate a multifile class with top-level functions and properties declared in this file as one of its parts. Name of the corresponding multifile class is provided by the JvmName annotation.

annotation class JvmMultifileClass
Common
JVM
1.0

JvmName

Specifies the name for the Java class or method which is generated from this element.

annotation class JvmName
Common
JVM
1.0

JvmOverloads

Instructs the Kotlin compiler to generate overloads for this function that substitute default parameter values.

annotation class JvmOverloads
Common
JVM
1.5

JvmRecord

Instructs compiler to mark the class as a record and generate relevant toString/equals/hashCode methods

annotation class JvmRecord
Common
JVM
1.8

JvmSerializableLambda

Makes the annotated lambda function implement java.io.Serializable, generates a pretty toString implementation and adds reflection metadata.

annotation class JvmSerializableLambda
Common
JVM
1.0

JvmStatic

Specifies that an additional static method needs to be generated from this element if it's a function. If this element is a property, additional static getter/setter methods should be generated.

annotation class JvmStatic
Common
JVM
1.0

JvmSuppressWildcards

Instructs compiler to generate or omit wildcards for type arguments corresponding to parameters with declaration-site variance, for example such as Collection<out T> has.

annotation class JvmSuppressWildcards
Common
JVM
1.0

JvmSynthetic

Sets ACC_SYNTHETIC flag on the annotated target in the Java bytecode.

annotation class JvmSynthetic
Common
JVM
1.0

JvmWildcard

Instructs compiler to generate wildcard for annotated type arguments corresponding to parameters with declaration-site variance.

annotation class JvmWildcard
JVM
1.0

PurelyImplements

Instructs the Kotlin compiler to treat annotated Java class as pure implementation of given Kotlin interface. "Pure" means here that each type parameter of class becomes non-platform type argument of that interface.

annotation class PurelyImplements
Common
JVM
1.0

Strictfp

Marks the JVM method generated from the annotated function as strictfp, meaning that the precision of floating point operations performed inside the method needs to be restricted in order to achieve better portability.

annotation class Strictfp

Synchronized

Marks the JVM method generated from the annotated function as synchronized, meaning that the method will be protected from concurrent execution by multiple threads by the monitor of the instance (or, for static methods, the class) on which the method is defined.

Common
JS
1.0
annotation class Synchronized
JVM
1.0
annotation class Synchronized
JVM
1.0

Throws

This annotation indicates what exceptions should be declared by a function when compiled to a JVM method.

annotation class Throws
Common
JVM
1.0

Transient

Marks the JVM backing field of the annotated property as transient, meaning that it is not part of the default serialized form of the object.

annotation class Transient

Volatile

Marks the JVM backing field of the annotated var property as volatile, meaning that reads and writes to this field are atomic and writes are always made visible to other threads. If another thread reads the value of this field (e.g. through its accessor), it sees not only that value, but all side effects that led to writing that value.

Common
JS
1.0
annotation class Volatile
JVM
1.0
annotation class Volatile

Exceptions

JVM
1.0

KotlinReflectionNotSupportedError

open class KotlinReflectionNotSupportedError : Error

Extensions for External Classes

JVM
1.0

java.lang.Class

Properties

JVM
1.0

annotationClass

Returns a KClass instance corresponding to the annotation type of this annotation.

val <T : Annotation> T.annotationClass: KClass<out T>
JVM
1.7

declaringJavaClass

Returns a Java Class instance of the enum the given constant belongs to.

val <E : Enum<E>> Enum<E>.declaringJavaClass: Class<E>
JVM
1.0

java

Returns a Java Class instance corresponding to the given KClass instance.

val <T> KClass<T>.java: Class<T>
JVM
1.0

javaClass

Returns the runtime Java class of this object.

val <T : Any> T.javaClass: Class<T>
val <T : Any> KClass<T>.javaClass: Class<KClass<T>>
JVM
1.0

javaObjectType

Returns a Java Class instance corresponding to the given KClass instance. In case of primitive types it returns corresponding wrapper classes.

val <T : Any> KClass<T>.javaObjectType: Class<T>
JVM
1.0

javaPrimitiveType

Returns a Java Class instance representing the primitive type corresponding to the given KClass if it exists.

val <T : Any> KClass<T>.javaPrimitiveType: Class<T>?

Functions

JVM
1.0

isArrayOf

Checks if array can contain element of type T.

fun <T : Any> Array<*>.isArrayOf(): Boolean