fork(1) download
  1. class Test {
  2. private static Integer value1 = getValue(); // This is causing to load again
  3.  
  4. private static Integer flag = null;
  5.  
  6. public static Integer getValue() {
  7. if (flag != null) { // if flag is loaded already, return it.
  8. return flag;
  9. }
  10.  
  11. System.out.println("Loading value...");
  12.  
  13. flag = Integer.valueOf(10);
  14.  
  15. return flag;
  16. }
  17.  
  18. public static void main(String[] args) {
  19. getValue();
  20. }
  21.  
  22. private static Integer value2 = getValue(); // This will not cause to load again
  23. }
Success #stdin #stdout 0.05s 711168KB
stdin
Standard input is empty
stdout
Loading value...
Loading value...