S
Sebastian Millies
I am confused about a statement in the API docs for java.math.BigDecimal
in J2SE 1.4.2. They state:
public static BigDecimal valueOf(long unscaledVal, int scale)
Translates a long unscaled value and an int scale into a BigDecimal.
This "static factory method" is provided in preference to a (long, int)
constructor because it allows for reuse of frequently used BigDecimals.
What is meant by "reuse" here? The valueOf method creates a new BigDecmal
based on a new BigInteger. So the API docs seem to refer to reuse by a
client. Am I missing something important here? My usual way of reusing
BigDecimals goes like this:
private static final BigDecimal CENT = new BigDecimal("0.01");
and plugging in the constant whenever I want to compute with cents.
Thanks,
Sebastian
in J2SE 1.4.2. They state:
public static BigDecimal valueOf(long unscaledVal, int scale)
Translates a long unscaled value and an int scale into a BigDecimal.
This "static factory method" is provided in preference to a (long, int)
constructor because it allows for reuse of frequently used BigDecimals.
What is meant by "reuse" here? The valueOf method creates a new BigDecmal
based on a new BigInteger. So the API docs seem to refer to reuse by a
client. Am I missing something important here? My usual way of reusing
BigDecimals goes like this:
private static final BigDecimal CENT = new BigDecimal("0.01");
and plugging in the constant whenever I want to compute with cents.
Thanks,
Sebastian