だからここに私のコードがあります:
public class SetWritable<T extends Writable> implements Writable {
private Class<? extends Writable> valueClass;
private Set<T> values;
public SetWritable(Class<T> valueClass) {
this.valueClass = valueClass;
this.values = new HashSet<T>();
}
public void readFields(DataInput in) throws IOException {
values = new HashSet<T>();
int len = in.readInt();
for (int i = 0; i < len; i++) {
//this line is where I get the warning
//FYI, WritableFactories.newInstance returns an instance of Writable
T value = (T) WritableFactories.newInstance(valueClass);
value.readFields(in);
values.add(value);
}
}
}
私を混乱させているのはこれです: T は Writable を拡張すると主張しましたが、Writable を T にキャストしようとすると警告が表示されるのはなぜですか? そして、T が Writable を拡張することを知っているので、この警告を抑制しても安全ですか?