Calling Kotlin from Java
Calling Kotlin from Java
Kotlin code can be called from Java easily.
Properties
A Kotlin property is compiled to the following Java elements:
- A getter method, with the name calculated by prepending the
get
suffix; - A setter method, with the name calculated by prepending the
set
suffix (only forvar
properties); - A private field, with the same name as the property name (only for properties with backing fields).
For example, var firstName: String
gets compiled to the following Java declarations:
private String firstName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; }
If the name of the property starts with is
, a different name mapping rule is used: the name of the getter will be the same as the property