Java from Kotlin
One of the main selling points for Kotlin over other alternative JVM languages is the importance placed upon a high degree of interoperability between Kotlin and Java. Most Java code can be called without any special support, and some special cases are described here.
Getters and setters
The JavaBean convention in Java states that mutable fields have a getter and a setter, and immutable fields just have a getter. A getter is just a no-arg method named get followed by the name of the field. A setter is a single argument method named set followed by the name of the field, where the argument is the value you want to set the field to:
public class Named { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } }
This pattern is standard across most of Java. In Kotlin, methods defined in this way can...