Java Reference
In-Depth Information
public static Statistics getInstance(){
synchronized(Statistics.class){
if (instance == null){
instance = new Statistics();
}
}
return instance;
}
Solution 2
First, create an enum and declare a single element named INSTANCE within it. Next,
declare other fields within the enum that you can use to store the values that are re-
quired for use by your application. The following enum represents a Singleton that will
provide the same abilities as solution 1:
import java.util.ArrayList;
import java.util.List;
public enum StatisticsSingleton {
INSTANCE;
private List teams = new ArrayList();
/**
* @return the teams
*/
public List getTeams() {
return teams;
}
/**
* @param teams the teams to set
*/
public void setTeams(List teams) {
this.teams = teams;
}
}
Search WWH ::




Custom Search