All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.SingleMethodSingleton.html Maven / Gradle / Ivy



SingleMethodSingleton

SingleMethodSingleton

Some classes contain overloaded getInstance. The problem with overloaded getInstance methods is that the instance created using the overloaded method is not cached and so, for each call and new objects will be created for every invocation.

This rule is defined by the following Java class: net.sourceforge.pmd.lang.java.rule.design.SingleMethodSingletonRule

Example(s):

public class Singleton {

   private static Singleton singleton = new Singleton( );
   
  private Singleton(){ }
   
public static Singleton getInstance( ) {
	  return singleton;
}
public static Singleton getInstance(Object obj){
	Singleton singleton = (Singleton) obj;
	return singleton;			//violation
}
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy