编译错误:Java不兼容类型

问题描述 投票:0回答:1

尽管IntelliJ IDE不会给我任何警告,但是这种两行方法会导致编译错误Error:(12, 37) java: incompatible types: byte[] cannot be converted to int

import java.math.BigInteger;

public class Test {

    public static void main(String[] args){
        String foo = "123";
        new BigInteger(foo.getBytes(), 1, 1);
    }
}

[我正在使用JDK 11,我可以看到这应该是对BigInteger构造函数(java.math.BigInteger的306行)的有效调用,该构造函数应作为签名public BigInteger(byte[] val, int off, int len)

我不明白为什么Java首先试图将byte []转换为int。


编辑:

这似乎是IntelliJ的问题,对于JDK 11,我可以直接用javac对其进行编译,并且可以工作,但对于JDK 8则不能。我已经将IntelliJ配置为使用JDK 11,但是我不知道为什么它使用的是旧版本...

java intellij-idea compiler-errors biginteger intellij-14
1个回答
0
投票

没有理由不能在Java9中使用。请在Java9中检查以下构造函数:

BigInteger​(byte[] val, int off, int len)

请检查https://docs.oracle.com/javase/9/docs/api/java/math/BigInteger.html

© www.soinside.com 2019 - 2024. All rights reserved.