Recommended Posts

How one can used function pointer technique used in c++ through java?
So that I can avoid lots of if- else structures for making a check.
If I get particular object then I want to directly call a method associated with it.
Please Help.

and suppose I have arr1[10] array of pointers which contains pointers to different ten functions which are used to handle specific obstacle collisions.

so if I am on screen number two and my game script gave me the information about that screen that obstacle 10 and 5 are present on this screen. then for collision and response I just want to used two function calls whithout any if else structure.

In Java, you can use interfaces for the same thing. Implement an interface with a single function, which is the method signature you want, and store a pointer to interface in your array. Then call that.

Note: you'd probably want to store the pointer to the obstacle, rather than the obstacle id. That way, you can call the method directly.