In Java, is there a way to emulate the first-class functions in lua and python, such as here?
def foo():
print "foo called"
bar = foo
bar() #output from this line is "foo called"
Or is the only way to have a switch statement with the different methods at each case?
Edit: thank you for the clarification, what I mean to ask is is there a way to create a reference to a function, and call it as if it was the function.
Also, the goal is not to call a certain implementation of a function, it is choose which function to call, the choices of which can entirely different. The reason I want to do this is to have a more general class that does not have to be edited to add functionality. Kind of like putting functions into a collection or list.
Edit2: for anybody viewing this question for the purpose of finding an answer to it: This has to do with stacks and heaps. Java cannot do this because its methods are stored on the stack, which is much more rigid than the heap. Python, however, stores its functions on the heap, with a reference to them on the stack. Since functions are called through a reference in python, you can change the reference to them and use as desired.