I'm reading J. Bloch's effective java and now I'm at the using function object item. He said that:
Java does not provide function pointers, but object references can be used to achieve a similar effect. Invoking a method on an object typically performs some operation on that object. However, it is possible to define an object whose methods perform operations on other objects, passed explicitly to the methods. An instance of a class that exports exactly one such method is effectively a pointer to that method.
What does that mean? I'd guess that everytime we create the object of such a class, we'll effectively get a function pointer within JVM
internally. But I'm not sure about that, becauase Java itself doesn't know the function pointer concept.
In other word, do we have just an optimization performed by compilers for such objects?
Example:
public interface Callback{
public void invoke();
}
public class GenericCallback implements Callback{
public void invoke(){ System.out.println("Generic callback"); }
}
public static void main(String[] args){
Callback c = new GenericCallback(); //What kind of optimization will
//be performed for the c object?
}