I'm a bit unsure of how I implemented something, and am hoping for some feedback.
I have a class, Metric, and it needs to multiply some numbers by a given percentage before returning them. They are returning BigDecimal, so I created class variable BigDecimal to store that percentage, then multiply them together on the return.
public class Metric extends Model {
private static final BigDecimal percentage = new BigDecimal("1.2");
public BigDecimal getMetric() {
return new BigDecimal(getValue()).multiply(percentage);
}
}
Is there any issue with a static final and declaring it right away with new? Also, I tried to research if BigDecimal is thread safe, and I couldn't find a for sure answer. Feedback on that would be appreciated.
BigDecimal
is immutable and thus thread-safe. Also, there is no problem with a static final value like that -- in fact, it's recommended.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With