简体   繁体   English

什么是Java的BigDecimalInstantiation PMD规则的xpath表达式

[英]What is the xpath expression for a BigDecimalInstantiation PMD rule for java

I want to create a custom PMD rule that eliminates instantiation of BigDecimal objects (ie. new BigDecimal(value) ). 我想创建一个自定义PMD规则,消除BigDecimal对象的实例化(即新的BigDecimal(值))。 I need to enforce the BigDecimal.valueof(value) implementation. 我需要强制执行BigDecimal.valueof(value)实现。

I have no idea how to implement this. 我不知道如何实现这一点。 Are there some examples i can use? 我可以使用一些例子吗?

Thanks, Bas Hendriks 谢谢,Bas Hendriks

You could use the implementation of IntegerInstantiation as an example. 您可以使用IntegerInstantiation的实现作为示例。

But make sure not to forbid the usage of all the BigDecimal constructors. 但请确保不要禁止使用所有BigDecimal构造函数。 There are only three BigDecimal.valueOf methods, and the ones taking a long as arguments are the only ones which should be preferred over calling a constructor. 只有三个BigDecimal.valueOf方法,并且采用long作为参数的方法是唯一应该优先于调用构造函数的方法。

The one taking a double just calls the constructor anyway, and constructing BigDecimal with double values should be discouraged anyway. 采用double的那个只是调用构造函数,并且不管怎样都不鼓励使用double值构造BigDecimal。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM