Slide 21
Slide 21 text
public final class ImmutableClassJava {
private final String name;
private final int age;
public ImmutableClassJava(String name, int age) {
this.name = name;
this.age = age;
}
// no setters
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
class ImmutableClass(val name: String,
val age: Int,
val grade: Char,
val hobbies: List)
● Class is final by default
● val implies that the parameters are final as well (values
can’t be assigned)
Immutability in Java vs Kotlin