I want to get rid of the FindBugs warning "DMI: Random object created and used only once". In the following example, the random number is generated only once upon the object construction. In other terms, for the lifecycle of a single instance of the class Wrap
, no other instances of java.util.Random
will be created. Is there a way to get rid of this warning (other than adding an annotation), specifically in the case where java.util.Random
is instantiated in the constructor ?
public final class Wrap {
/**
* Random generated double.
*/
private final double random;
/**
* Constructor.
*/
public Wrap() {
this.random = new Random().nextDouble();
}
public Double value() {
return this.random;
}
}
Aucun commentaire:
Enregistrer un commentaire