I want to create a custom PMD rule that eliminates instantiation of BigDecimal objects (ie. new BigDecimal(value) ). I need to enforce the BigDecimal.valueof(value) implementation.
I have no idea how to implement this. Are there some examples i can use?
Thanks,
Bas Hendriks
You could use the implementation of IntegerInstantiation as an example.
But make sure not to forbid the usage of all the BigDecimal constructors. There are only three
BigDecimal.valueOfmethods, and the ones taking a long as arguments are the only ones which should be preferred over calling a constructor.The one taking a double just calls the constructor anyway, and constructing BigDecimal with double values should be discouraged anyway.