Hi there, What is the idiomatic Kotlin way to exp...
# announcements
a
Hi there, What is the idiomatic Kotlin way to expose a
var
as a read-only property. I need something like the following:
Copy code
class Something(...) {
var counter_ = 0

fun doSomething() { 
(snip)
counter_++
(snip)
}

val counter: Int get() = counter
Is there a better way?
r
Copy code
var counter = 0
   private set
👍 6
publicly its read-only but can be modified inside the class
a
@Rami Baksansky thanks a bunch!