java.math.BigInteger cannot be cast to java.lang.Integer

后端 未结 5 1842
予麋鹿
予麋鹿 2020-12-13 09:48

I\'m getting the following exception.

Caused by:

java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Integer

5条回答
  •  借酒劲吻你
    2020-12-13 10:47

    As we see from the javaDoc, BigInteger is not a subclass of Integer:

    java.lang.Object                      java.lang.Object
       java.lang.Number                       java.lang.Number
          java.math.BigInteger                    java.lang.Integer
    

    And that's the reason why casting from BigInteger to Integer is impossible.

    Casting of java primitives will do some conversion (like casting from double to int) while casting of types will never transform classes.

提交回复
热议问题