(I use kotlin 1.1.2-2)
I found there are 2 ways to define property that is variable but cannot be assigned through =.
varwith private settervalwith private variable backing property
I also found they have different behaviour.
When T is declared out, var of type T with private setter cannot be defined while val with backing property is legitimate.
open class A<out T>(v: T) {
// error because T occurs in invariant position
var prop1: T = v
private set
private var _prop: T = v
val prop2: T get() = _prop
}
Why prop1 is invariant position and prop2 is not? Where does the difference come from?