8
When we create a variable of type val
, in the case of Java, only the getter
relative to it. Different when a type variable is created var
, in which the getter
and setter
. See below for 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 a customization of getter
in Java, for example using the toUpperCase
so that the result returns in "high box" when it comes to a string:
public final String getContent() {
return this.content.toUpperCase();
}
Following this concept, what would be the best way to customize the getter
in Kotlin?
I improved my answer. I thought it was important to warn you =D
– Jéf Bueno
Who denied the question could at least explain the reason why I can edit it and try to collaborate more with our community.
– viana