When we create a variable of type val
, in the case of Java, only getter
is created in relation to it. Different when a variable of type var
is created, in which getter
and setter
is created. Here is an example:
Kotlin using val
:
class Article construtor(content: String){
val content: String = content
}
Equivalence in Java :
public class Article {
private String content;
public final String getContent() {
return this.content;
}
public Article(String content) {
this.content = content;
}
}
See below for a custom customization of getter
in Java, using for example the toUpperCase
method so that the result returns in the "uppercase" when it is a string :
public final String getContent() {
return this.content.toUpperCase();
}
Following this concept, what would be the best way to customize getter
in Kotlin?