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;
             } else
                 flag=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();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值