Unchecked or unsafe operations

编程入门 行业动态 更新时间:2024-10-26 17:18:58

<a href=https://www.elefans.com/category/jswz/34/1684896.html style=Unchecked or unsafe operations"/>

Unchecked or unsafe operations

在写泛型的BST时,javac -xlint test.java,出现Warning: Unchecked or unsafe operations。

 public E next() {Node nextNode=null;boolean flag=true;while(flag) {if (current != null) {stack.push(current);current = current.left;} else {current = stack.peek();if (current.right != null && pre != current.right) {current = current.right;} elseflag=false;}}pre=stack.pop();current=pre;nextNode=current;current=null;return (E)nextNode.val;}

出错语句:return (E)nextNode.val;
提示没有检查类型。
这里是java设计的问题。加一句@SuppressWarnings("unchecked")即可。
另外还有一段也报同样的错。因为我extends了comparable,重写了equals。这里如果没有重写hashCode就会继续报警告,提示重写了equals而没有写hashCode。
为什么重写一个就要重写另一个?
是因为Java规定,如果a.equals(b)==0,则a.hashCode()==b.hashCode();

更多推荐

Unchecked or unsafe operations

本文发布于:2024-03-08 02:56:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1719649.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Unchecked   unsafe   operations

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!