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
ephemient
11/19/2024, 2:06 AM
that would be a breaking change
ephemient
11/19/2024, 2:07 AM
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
ephemient
11/19/2024, 2:07 AM
I don't think it makes sense when we already have a sensible way to express