代码:
interface BaseIntr<T>{
void saveSwiftMsg(Collection<String> headers) throws Exception;
}
class Impl implements BaseIntr{
public void saveSwiftMsg(Collection<String> headers) throws Exception { }
}
代码的编辑版本:
interface BaseIntr<T>{
T process(T t);
void saveSwiftMsg(Collection<String> headers) throws Exception;
}
class Impl implements BaseIntr{
public void saveSwiftMsg(Collection<String> headers) throws Exception { }
@Override
public Object process(Object t) { return t; }
}
工作环境:
Java 版本:1.7.0_04,供应商:甲骨文公司
默认语言环境:en_IN,平台编码:Cp1252
操作系统名称:“windows 7”,版本:“6.1”,arch:“amd64”,家族:“windows”
java 编译器抛出以下异常。但是如果我从 BaseIntr 中删除 < T >,它就可以正常工作。
javac gen\GenericsTest.java
gen\GenericsTest.java:18: error: Impl is not abstract and does not override abstract method saveSwiftMsg(Collection) in BaseIntr
class Impl implements BaseIntr{
^
gen\GenericsTest.java:20: error: name clash: saveSwiftMsg(Collection<String>) in Impl and saveSwiftMsg(Collection<String>) in BaseIntr have the same erasure, yet neither overrides the other
public void saveSwiftMsg(Collection<String> headers) throws Exception {
^
2 errors