hacker rank 53rd java (java singleton pattern)
53. java singleton pattern
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.reflect.*;
class Singleton {
private volatile static Singleton object;
public static String str;
private Singleton() {}
static Singleton getSingleInstance() {
if (object == null) {
synchronized (Singleton.class) {
if (object == null) {
object = new Singleton();
}
}
}
return object;
}
}
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.reflect.*;
class Singleton {
private volatile static Singleton object;
public static String str;
private Singleton() {}
static Singleton getSingleInstance() {
if (object == null) {
synchronized (Singleton.class) {
if (object == null) {
object = new Singleton();
}
}
}
return object;
}
}
Comments