Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
/java:15:错误:不兼容的类型:从int到byte-byte-myTotalByte=(myMinByteValue/2)的可能有损转换;^1错误_Java - Fatal编程技术网

/java:15:错误:不兼容的类型:从int到byte-byte-myTotalByte=(myMinByteValue/2)的可能有损转换;^1错误

/java:15:错误:不兼容的类型:从int到byte-byte-myTotalByte=(myMinByteValue/2)的可能有损转换;^1错误,java,Java,错误:-/Main.java:15:错误:不兼容的类型:从int到byte的可能有损转换 字节myTotalByte=(myMinByteValue/2); ^ 1错误有两种方法可以将字节类型变量设置为最终: class Main { public static void main(String[] args) { int myMinIntValue = Integer.MIN_VALUE; System.out.println("MY INteger

错误:-/Main.java:15:错误:不兼容的类型:从int到byte的可能有损转换 字节myTotalByte=(myMinByteValue/2); ^
1错误

有两种方法可以将
字节
类型变量设置为
最终

class Main {
    public static void main(String[] args) {

        int myMinIntValue = Integer.MIN_VALUE;
        System.out.println("MY INteger Value is =" + myMinIntValue);
        byte myMinByteValue = Byte.MIN_VALUE;
        System.out.println("MY byte Value is =" + myMinByteValue);

        int myTotal = (myMinIntValue);
        System.out.println(myTotal);

        byte myTotalByte = (myMinByteValue / 2);
        System.out.println(myTotalByte);

    }
}
您可以
将其强制转换为
字节
,并明确告知编译器

final byte myMinByteValue = Byte.MIN_VALUE;

要了解更多信息,请访问java

2
类型为
int
,您必须将其转换为:

byte myTotalByte = (byte) (myMinByteValue / 2);
那是iirc,因为我现在不在电脑前

byte myTotalByte = myMinByteValue / (byte)2;

2
是一个整数文本,因此结果也是一个整数。但是,即使您编写
myMinByteValue/(byte)2
,它仍然是一个整数,因为
int
是JVM中的最小类型大小(
byte
在JVM内部被视为
int
)。

将它转换为byteIt,在我尝试除法(myminitvalue/2)时它已经起作用了…但不是(myMinByeValue/2)..<代码>字节myTotalByte=(字节)(myMinByteValue/2)它也将不起作用,并将得到相同的错误。
 byte myTotalByte = (byte)(myMinByteValue / 2);