Variable functions in Java

user1845673 picture user1845673 · Nov 22, 2012 · Viewed 8k times · Source

Is it possible through some method to assign a function to a variable in Java, like in PHP or JavaScript?

...Or does this area works on a different way when it comes to Java?

Answer

Peter Lawrey picture Peter Lawrey · Nov 22, 2012

In Java you have Method and MethodHandles which can invoke a method via reflection but that is not supported in the language yet.

In Java 8, you will be able to use references to methods.