我剛剛安裝了jdk1.7.0_07,我突然淹沒了大量關於通用原始類型的警告。 (我收到了數百個,他們混淆了其他可能有意義的警告。)據我所知,這些錯誤不應該生成,並且我沒有使用java-6-openjdk-i386獲取它們。通用類型轉換
我創建了下面的小例子。 (每一類在它自己的文件。)
public interface Generic<T> {
public T get();
}
public class Test {
public Test safeAsHell(Generic thing, int number) {
return new Test();
}
public void safeAsHell(Generic thing) { }
}
當我嘗試編譯該文件(javac -Xlint),我得到以下警告:
Test.java:3: warning: [rawtypes] found raw type: Generic
public Test safeAsHell(Generic thing, int number) {
^
missing type arguments for generic class Generic<T>
where T is a type-variable:
T extends Object declared in interface Generic
Test.java:7: warning: [rawtypes] found raw type: Generic
public void safeAsHell(Generic thing) { }
^
missing type arguments for generic class Generic<T>
where T is a type-variable:
T extends Object declared in interface Generic
2 warnings
添加Object
作爲泛型類型參數( Generic<Object> thing
)解決了這個問題。我曾認爲類型Generic
和Generic<Object>
是等效的。我可以忽略一些東西嗎
http://stackoverflow.com/questions/6783316/list-vs-listobject –