Question
I know this question has been asked before, but either the answers don't apply to this case, or I don't understand them. Basically, why doesn't the following (simple example that recreates my problem) work ?
- class Test[+T] {
- var list: List[T] = _
- }
How-To
Making Test covariant in T means that Test[A] is a subtype of Test[Any] for any A. So lets create a Test:
- val test_string = new Test[String]
- val test_any : Test[Any] = test_string
- test_any.list = List[Any]()
Supplement
* Scala Gossic : 繼續深入 - 型態參數化 (Covariance)
沒有留言:
張貼留言