Is there a proposal in Kotlin to allow primary con...
# random
j
Is there a proposal in Kotlin to allow primary constructor parameters without val to be used as private val? In C#, primary constructor parameters can be implemented either as simple constructor arguments or with private backing fields, depending on how they are used. What are your thoughts on this approach?
e
that would be a breaking change
Copy code
val x = 0
class Foo(x: Int) {
    fun frob() = println(x)
}
in current Kotlin,
Foo(1).frob()
prints 0 if it were silently upgraded to
Copy code
class Foo(private val x: Int) {
    fun frob() = println(x)
}
then
Foo(1).frob()
would print 1
I don't think it makes sense when we already have a sensible way to express
private val
either
👍 1
j
Didn't know the breaking change. It makes sense.