문제

In the book I use to prepare for the new Oracle Certified Professional - Java SE7 Programmer exam, in the section that deals with method overriding, I have come across the following:

The overriding method should have the same argument list types (or compatible types) as the base version.

What do they mean by "compatible types"? I mean, as soon as the argument list types differ, you're overloading, not overriding.

I can only think of overriding a method that takes varargs arguments, with one that takes an array of the same type. Compiler gives a warning, but compiles still.

What do they mean by compatible types? Is that an error in the book?

도움이 되었습니까?

해결책

Maybe it has something to do with type erasure. This is valid Java, it just gives you a warning:

abstract class Foo {
    public abstract void method(List<String> xs);
}

class Bar extends Foo {
    @Override
    public void method(List xs) {
    }
}

The raw type List is compatible with List<String>.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top