Search code examples
javafunctionvariablesdynamic-function

Variable functions in Java


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?


Solution

  • 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.