整数的哈希集

1 java generics inheritance abstract-class hashset

public class MyClass<Integer> extends AnotherOne<Integer> {
    public MyClass(HashSet<Integer> ar) {    
        super(ar);
    } 
}
Run Code Online (Sandbox Code Playgroud)

AnotherOne是一个抽象(通用)类,它有一个HashSet<T>作为参数的构造函数。然后它有另一种方法,该方法使用该T类型作为其参数。

一切正常,但我必须Integer用作参数来覆盖该方法,而使用Integer而不是int看起来很奇怪。有没有办法使用原始int?

pet*_*rov 5

不,您不能将原始 int 用于 HashSet。

这也适用于所有其他泛型集合类。