October 2019
Intermediate to advanced
434 pages
11h 54m
English
You might have noticed that, in the previous example, we were able to access the newly added title property without having added a getter. This is possible because Kotlin will generate getters and setters for us for properties with simple accessor logic. Let's look more closely at the following code:
In this snippet, we have our Course class with a public title property:
class Course(courseTitle: String) { val title = courseTitle}
From Kotlin, we can access that property name directly, as follows:
val courseTitle = course.title
However, from Java, we must access that property using a generated getter:
String courseTitle = course.getTitle();
From Kotlin, we can access the property by referencing its name directly without ...
Read now
Unlock full access