“可能的精度损失”是Java疯了还是我错过了什么? [英] "possible loss of precision" is Java going crazy or I'm missing something?
本文介绍了“可能的精度损失”是Java疯了还是我错过了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是一个实例变量:
byte move = 0;
这是在这个类的方法中发生的:
this.move =(this.move<< 4)|(byte)(Guy.moven.indexOf(left)& 0xF);
move是一个字节,move仍是一个字节,其余的被转换为一个字节。
我收到此错误:
[javac] / Users / looris / Sviluppo / dumdedum / client / src / net / looris / android / toutry / Guy.java:245:可能丢失精度
[javac] found:int
[javac] required:byte
[javac] this.move =(this.move<< 4)|(byte)(Guy.moven.indexOf(left)& 0xF);
[javac] ^
我尝试过很多变化, 。
我现在无能为力。
解决方案
operatos(& | ^)返回 int ,而不考虑它们的操作数。您还必须投射x | y的最终结果。
I'm getting a "loss of precision" error when there should be none, AFAIK.
this is an instance variable:
byte move=0;
this happens in a method of this class:
this.move=(this.move<<4)|(byte)(Guy.moven.indexOf("left")&0xF);
move is a byte, move is still a byte, and the rest is being cast to a byte.
I get this error:
[javac] /Users/looris/Sviluppo/dumdedum/client/src/net/looris/android/toutry/Guy.java:245: possible loss of precision
[javac] found : int
[javac] required: byte
[javac] this.move=(this.move<<4)|(byte)(Guy.moven.indexOf("left")&0xF);
[javac] ^
I've tried many variations but I still get the same error.
I'm now clueless.
解决方案
Actually all logic operatos (& | ^) return an int, regardless of their operands. You have to cast the final result of x|y as well.
这篇关于“可能的精度损失”是Java疯了还是我错过了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文