fork download
  1.  
  2. class Program {
  3. public static void main(String[] args){
  4. System.out.printf("zow = %h \n", Zow.ZOW_SINGLETON_REF.getZow());
  5.  
  6. ZowReference refZowTwo = Zow.ZOW_SINGLETON_REF.getZow().dive(Zow.ZOW_SINGLETON_REF);
  7. System.out.printf("zow2 = zow.dive(zow); %h ← %h\n", refZowTwo.getZow(), Zow.ZOW_SINGLETON_REF.getZow());
  8.  
  9. ZowReference refZowThree = Zow.ZOW_SINGLETON_REF;
  10. System.out.printf("zowOne == zowTwo : %s\n", Zow.ZOW_SINGLETON_REF.getZow() == refZowTwo.getZow());
  11. System.out.printf("zowOne == zowThree : %s\n", Zow.ZOW_SINGLETON_REF.getZow() == refZowThree.getZow());
  12. }
  13. }
  14.  
  15. class Zow {
  16. private static final Zow zowSingleton = new Zow();
  17.  
  18. public static final ZowReference ZOW_SINGLETON_REF = new ZowReference(zowSingleton);
  19.  
  20. public ZowReference dive(ZowReference refZow2) {
  21. System.out.printf("zow2 = %h\n", refZow2.getZow());
  22. refZow2.setZow(new Zow()); // compile error.
  23. System.out.printf("zow2 = %h\n", refZow2.getZow());
  24.  
  25. return refZow2;
  26. }
  27. }
  28.  
  29. class ZowReference {
  30. private final Zow zow;
  31.  
  32. public ZowReference(Zow zow) {
  33. this.zow = zow;
  34. }
  35.  
  36. public Zow getZow() {
  37. return this.zow;
  38. }
  39. }
  40.  
  41.  
  42.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:22: error: cannot find symbol
		refZow2.setZow(new Zow()); // compile error.
		       ^
  symbol:   method setZow(Zow)
  location: variable refZow2 of type ZowReference
1 error
stdout
Standard output is empty