Property without getter in Kotlin

Viewed 1734

How can I declare a property with a custom setter, but without getter in Kotlin? In Anko for example they do it like this:

var myProperty: Type
    @Deprecated(AnkoInternals.NO_GETTER, level = DeprecationLevel.ERROR) 
    get() = AnkoInternals.noGetter()
    set(value) { field = value; /* setter logic */ }

But it looks a bit hacky to me. Is this a right way to do so? If yes, then what about the case when a project doesn't have Anko dependency?

P.S. Let me be clear - I want to have no getter at all, rather than private getter

2 Answers

voddan's answer was great, but I can also supplement it with how I implemented it:

@get:Deprecated(message = "no.", level = DeprecationLevel.ERROR)
lateinit var property: Any

here I use the lateinit modifier and the @Deprecated annotation for the getter.

Related