Overview
Sometimes you may need to implement a Java interface for a Kotlin class. In the post, we are going to discuss how to override Java-style getters and setters for a Kotlin class.
Example
Suppose we have the following Java interface:
public interface A {
Long getId();
boolean isNew();
}
Because Kotlin properties do not override Java-style getters and setters you have to add a private modifier for property and override a method in a Kotlin class:
class B(
private val id: Long,
private val new: Boolean
): A {
override fun getId() = id
override fun isNew() = new
}
Conclusion
We have described how to override Java-style getters and setters for a Kotlin class.
-
Previous
How to create an entity for a view with the help of the Hibernate -
Next
How to fix an exception at the first call with Zuul1 gateway