In kotlin we can define
var text: String
which will have a getter and setter. It's easy to remove the installer by changing it to val, but what if we have a property that should only have a setter and no getter? Is there a way to create an annotation that we can apply to textthat will invalidate the getter so that others cannot use it?
The ultimate goal is to use property syntax rather than calling setText
The current workaround I know achieves a similar result:
var text: String
@Deprecated(level = DeprecationLevel.ERROR, message = "Non readable property")
get() = nonReadable()
set() ...
I would like to know if it is possible to define something similar to
@SetterOnly
var text: String
set() ...
source
share