File: t5120.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (29 lines) | stat: -rw-r--r-- 639 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Cell[T](x0: T) {
  type U = T
  var x1: U = x0
}

object Test {
  val str: Cell[String] = new Cell("a")
  val other: Cell[Int]  = new Cell(0)

  def main(args: Array[String]): Unit = {
    List(str, other) foreach (_.x1 = new AnyRef)
    str.x1.length
  }
}
// another way demonstrating the same underlying problem, as reported by Roman Kalukiewicz

class Holder[_T](_f1 : _T, _f2 : _T) {
  type T = _T
  var f1 : T = _f1
  var f2 : T = _f2
}
object Test2 {
  val str = new Holder("t1", "t2")
  val num = new Holder(1, 2)
  List(str, num).foreach(h => h.f1 = new Thread())
  def main(args: Array[String]) {
    println(str.f1)
  }
}