Advertisement
Thibstars

IntelliJ SingletonLazyInitialization Template

Jan 9th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
  2. #parse("File Header.java")
  3. public final class ${NAME}{
  4.     private static ${NAME} classInstance = null;
  5.  
  6.     private ${NAME}() {
  7.         //Constructor not publicly available
  8.     }
  9.  
  10.     public static synchronized ${NAME} getInstance() {
  11.         if(classInstance == null) {
  12.             classInstance = new ${NAME}();
  13.         }
  14.         return classInstance;
  15.     }  
  16.    
  17.     @Override
  18.     protected Object clone() throws CloneNotSupportedException {
  19.         return super.clone();
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement