by Leon · 10y ago · 0 comments
Specifically for this example:
System.out.println("\nVariable in method reference");
obj = new Counter(); // NPE if after method reference declaration!
final Runnable varRef = obj::show;
System.out.println("Running...");
varRef.run(); obj = new Counter(); varRef.run();
obj::show was evaluated, so varRef should be pointing to the original instance method of show, even when called the second time. Which could potentially create a memory leak if someone is tracking the method references and recreating objects underneath unknowingly.However if I am completely wrong about this please tell me! I have not gone through and run this code for confirmation, so I would be very happy to know if I'm mistaken. I'm going by memory without reference checking or testing. In either case if I am wrong or right - please put a note about this situation! It would help immensely and make your post even more interesting.
Thanks!
Leon
No comments yet.