I'm currently writing a KOTLIN class were I like to use the possibility of DSL but be backwards compatible for JAVA developers. When using a var
the compiler automatically creates getter and setter for JAVA, but those can't be used Builder style since they are not returning this
.
So basically what I like to do is something like this:
class MyClass {
// for use in KOTLIN only DSL style e.g. MyClass() { offset = 1 }
var offset: Int? = null
// for use in JAVA only BUILDER style e.g. new MyClass().withOffset(1)
fun withOffset(value: Int) = apply { offset = value }
}
In Kotlin I like to use, but don't want to have access to the withOffset
fun:
val myClass = MyClass() { offset = 1 }
In JAVA I like to use, but don't want to have access to the auto created setOffset
and getOffset
:
MyClass myClass = new MyClass().withOffset(1)
Renaming the getter and setter is possible via @JvmName
annotation already, but is there a annotation for hiding a public property for JAVA completly and optional of course vice versa?