Since Java doesnt support pointers, How is it possible to call a function by reference in Java like we do in C and C++??
The best way is to use an interface which performs the action.
// Pass a Runnable which calls the task() method
executor.submit(new Runnable() {
public void run() {
task();
}
});
public void task() { }
You can use reflections to call any method
Method method = MyClass.class.getMethod("methodToCall", ParameterType.class);
result = method.invoke(object, args);