blob: 7092d91314e4e19e7bf5f9537a0cceee1959022c (
plain) (
blame)
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
|
// A tricky case of overriding behavior
// Note: It might be acceptable if this produced an error instead.
// But testing this is tricky.
abstract class Base[T] {
def foo(x: T): String
}
class C[T] extends Base[T] {
def foo(x: D): String = "D foo"
def foo(x: T): String = "T foo"
}
object Test {
def main(args: Array[String]) = {
val b1: Base[D] = new C[D] // which of the two foo's in C overrides the one in B?
assert(b1.foo(new D) == "T foo")
val b2: Base[D] = new C[D] {}
// In Java, this gives an error like this:
// methods foo(A) from C[D] and foo(String) from C[D] are inherited with the same signature
// But the analogous example with `b1` compiles OK in Java.
assert(b2.foo(new D) == "T foo")
}
}
class D
|