June 2018
Intermediate to advanced
316 pages
6h 34m
English
If you want to declare just a field with the public modifier and without a getter and setter, you can use the @JvmField annotation. In this case, we should follow the concept of object-oriented programming and encapsulate data and operations. But sometimes, we need a simple class such as Point, which can be used as follows:
val point = Point(3, 4)point.x = 10
A naive approach in Kotlin is to create a class like this:
class Point(var x: Int, var y: Int)
If you decompile this class to Java, you'll see something like this:
public final class Point { private int x; private int y; public final int getX() { return this.x; } public final void setX(int var1) { this.x = var1; } public final int getY() { return this.y; } public ...
Read now
Unlock full access