Scala: Mixing traits with private fields
- by Vilius Normantas
It's not much of a question, it's rather my excitement that it's possible at all! I wrote this little example just to prove the opposite - I expected either a compiler error or one of the values (111 or 222, I wasn't sure).
scala> trait T1 { private val v = 111; def getValueT1 = v }
scala> trait T2 { private val v = 222; def getValueT2 = v }
scala> class T12 extends T1 with T2
scala> val t = new T12
scala> t.getValueT1
res9: Int = 111
scala> t.getValueT2
res10: Int = 222
Why doesn't the v get overridden? Off course this works only as long as vs are private, but still.