类型 E 被识别为对象
Type E recognized as an Object
为什么我要这样写:
Node<Vertex<E>, Double> a = queue.extractMax();
Vertex<E> u = a.getValue();
代码编译没有错误,如果我这样写:
Vertex<E> u = queue.extractMax().getValue();
我收到错误:
error: incompatible types: Object cannot be converted to Vertex
假设您的 extractMax()
signature/return 类型不同于 Node<Vertex<E>, Double>
-
Vertex<E> u = ((Node<Vertex<E>, Double>) queue.extractMax()).getValue();
根据您的示例,这个应该绝对有效。
为什么我要这样写:
Node<Vertex<E>, Double> a = queue.extractMax();
Vertex<E> u = a.getValue();
代码编译没有错误,如果我这样写:
Vertex<E> u = queue.extractMax().getValue();
我收到错误:
error: incompatible types: Object cannot be converted to Vertex
假设您的 extractMax()
signature/return 类型不同于 Node<Vertex<E>, Double>
-
Vertex<E> u = ((Node<Vertex<E>, Double>) queue.extractMax()).getValue();
根据您的示例,这个应该绝对有效。