如何解决优先队列中二进制运算符“-”的错误操作数类型
我如何摆脱此消息?
.green-bg {
/* Set the display to `table-row` because Vuetify makes `flex` */
display: table-row;
}
.green-bg:hover {
/* `!important` is necessary here because Vuetify overrides this */
background: green !important;
}
bad operand types for binary operator '-'
Queue<Long> heap = new PriorityQueue( (a,b)->b - a );
first type: Object
second type: Object
解决方法
使用非原始PriorityQueue
,并将减法的结果强制转换为int
:
Queue<Long> heap = new PriorityQueue<>( (a,b)-> (int) (b - a) );
当然,如果长短之差超过int
的范围,这将带来意想不到的结果。
使用起来更容易:
Queue<Long> heap = new PriorityQueue<>(Comparator.reverseOrder());
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。