How to define a internal `var` property that only ...
# getting-started
j
How to define a internal
var
property that only its
get
is
PublishedApi
?
It’s a field-like property. Get and set just delegate to the backing field.
j
Have you tried the syntax
@get:PublishedApi
to annotate only the getter?
v
Otherwise have a public val that delegates to a private var.
j
But that would be quite different, the getter would be more visible than a published internal and the setter less visible than an internal
v
Ok, I might have misinterpreted "published api". Well then a published api internal val delegating to a non-published api internal var. But if just annotating the getter works, then of course that, you just didn't sound confident that it will work, just that it maybe could work. 🙂
j
Well then a published api internal val delegating to a non-published api internal var
Yep, that makes sense if the annotation is not supported on the getter only
you just didn't sound confident that it will work
Yeah I'm not confident because I never played with
@PublishedApi
directly, so I prefer to write with caution 🙂 but I see no reason why it shouldn't work
j
I rewrote it into a
@PublishedApi
function that returns the value of a private var. Thanks for the answers.
j
Did annotating the getter not work?
Copy code
@get:PublishedApi
internal var x: Int = 42
Or did you just prefer with a function?
v
So basically my initial suggestion with added boilerplate 😄
😄 1
j
I just preferred. I might test that later.