fork(1) download
  1. private static void CachedAndSameValue()
  2. {
  3. System.out.println("CachedAndSameValue: \n");
  4. Integer a = 2;
  5. System.out.println(a);
  6.  
  7. Integer b = 2;
  8. System.out.println(b);
  9.  
  10. // This prints "equal" because 'a' and 'b' are stored in the same Integer instance, and "==" is comparing the references
  11. if(a == b)
  12. {
  13. System.out.println("equal");
  14. }
  15. else
  16. {
  17. System.out.println("not equal");
  18. }
  19. }
  20.  
  21. private static void CachedAndDifferentValue()
  22. {
  23. System.out.println("CachedAndDifferentValue: \n");
  24. Integer a = 2;
  25. System.out.println(a);
  26.  
  27. Integer b = 3;
  28. System.out.println(b);
  29.  
  30. // This prings "not equal" - but shouldn't it also print "equal" for the same reason above?
  31. if(a == b)
  32. {
  33. System.out.println("equal");
  34. }
  35. else
  36. {
  37. System.out.println("not equal");
  38. }
  39. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty