Java可能从int到byte错误的有损转换 [英] Java Possible lossy conversion from int to byte errors

查看:814
本文介绍了Java可能从int到byte错误的有损转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从jar文件反编译一些类时发生了这种情况。这些是我无法解决的唯一错误。

This happened when I decompiled some classes from a jar file. These are the only errors I cannot get past.

所有这些错误都是'从int到byte的可能有损转换'。

All of these errors are 'Possible lossy conversion from int to byte'.

this.onDemandFetcher.method563(1, 2, i2);
this.worldController.method291(i1, j, i, -119);
this.method563(2, 3, this.mapIndices3[k]);
this.method563(2, 3, this.mapIndices2[k]);

public boolean method286(final int j, final int k, final Animable class30_sub2_sub4, final int l, final int i1, final int j1, final int k1, final int l1, final int i2, final int j2, final int k2) {
        return class30_sub2_sub4 == null || this.method287(j, l1, k2, i2 - l1 + 1, i1 - k2 + 1, j1, k, k1, class30_sub2_sub4, l, true, j2, 0);
    }

return this.method287(i, l2, i2, j2 - l2 + 1, k2 - i2 + 1, k1, i1, k, class30_sub2_sub4, j, true, l, 0);

所有这些错误都归为同一类。我究竟做错了什么?你能帮我修一下代码并告诉我差异吗?

All of these errors are classified as the same thing. What exactly am I doing wrong? Could you please fix the code for me and show me the difference?

推荐答案

从int到byte的可能有损转换意味着你的代码的某些部分想要一个字节,并且你传递一个int。字节数为8位且为32位,因此通过执行此转换可能会丢失信息。

"Possible lossy conversion from int to byte" means that some part of your code wants a byte, and you are passing it an int. Bytes are 8 bits and ints 32, so information may be lost by doing this conversion.

您还没有发布足够的代码来了解,但它可能在method287的参数。如果它想要字节,那么传递int变量将触发此错误。您还应该记住,默认情况下整数常量是整数 - 如果需要,可以将它们转换为字节。

You haven't posted enough of the code to know, but it's probably in the arguments to method287. If it wants bytes, then passing it the int variables will trigger this error. You should also remember that whole-number constants are ints by default - you can cast them to bytes if you need it.

现在你知道这个消息意味着你应该是什么能够查看代码并检查这些转换发生的位置。

Now you know what the message means you should be able to go through the code and check where these conversions occur.

这篇关于Java可能从int到byte错误的有损转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆