I have a java program that I am testing and a lot of the code is centered around the idea that a coin can have a value null. The issue, the coin is defined using Coin(BigDecimal) and I cannot figure out how to convert the Bug Decimal Part to represent null.
How Can I Create A BigDecimal Object that has null as it's value
107 views Asked by River Uzoma At
2
There are 2 answers
0
On
You can define BigDecimal.ZERO your coin variable instead of defining null.
According to document
All methods and constructors for this class throw NullPointerException when passed a null object reference for any input parameter.
Just assign
nullto yourBigDecimalreference variable, as you would for any other class.Example class defined as a record.
Usage with null.