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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
class Bar[@specialized(Int, AnyRef) A](a: A) {
val memb = a
}
class WithInner[@specialized(Int, AnyRef) A](a: A) {
class Inner {
def meth = a
}
}
class Baz[@specialized(Int, AnyRef) A, @specialized(Int, AnyRef) B] {
def ab(a: A, b: B) = (a, b)
}
trait Base[@specialized(Int, AnyRef) A]
class Concrete[@specialized(Int, AnyRef) A] extends Base[A]
class WithAnon[@specialized(Int, AnyRef) A](a: A) {
new AnyRef {
def foo = a
}
}
class Norm {
def id[@specialized(Int, AnyRef) A](a: A) = a
}
class Qux[@specialized(AnyRef) A] {
def memb[@specialized(AnyRef) B](a: A, b: B) = (a, b)
}
class Foo[@specialized(Int, AnyRef) A](val a: Array[A]) {
a(0)
def id(elem: A) = a(0) = elem
}
// instantiation and selection
object Test {
def main(arg: Array[String]) {
val f = new Foo(new Array[String](5))
f.id("")
val z = new Baz[Int, Double]
z.ab(1, 1.0)
testspec(new Array[String](5))
testspec(new Array[Int](5))
}
def testspec[@specialized(Int, AnyRef) T](arr: Array[T]) = arr(0)
}
|