1

We can store

Integer a= 12;

But we can't store like this

BigDecimal b =12;// what is the reason for that
seenukarthi
  • 8,241
  • 10
  • 47
  • 68
  • 7
    Because there is no autoboxing conversion for the arbitrary precision types `BigDecimal` *or* `BigInteger`. The actual boxing conversions are [documented](https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.1.7). – Elliott Frisch Nov 28 '21 at 05:44

1 Answers1

6

BigDecimal is not a primitive. In order to have a BigDecimal you need to create an instance of it like BigDecimal b = new BigDecimal(12);. From there you can call its various methods to do math with it, round it, etc.

With very, very few exceptions all Java Objects require that you assign the variable with an object of that type (or whatever follows the rules of polymorphism).