0

I'm building a game in libgdx where I need to notify someclass about an explosion that occured. Now, I have access to that exact same moment when it occurs. How exactly do I notify my class that an explosion has happened?

I read this: http://www.javaworld.com/article/2077462/learn-java/java-tip-10--implement-callback-routines-in-java.html

But I didn't understand the concept of callbacks. I understand that it is a way to notify classes and objects that an event has happened but I'm not sure how to implement this. If you guys could clarify that for me I would really appreaciate it!

0

1 Answer 1

2

A callback is commonly used in asynchronous programming, so you could create a method which handles the response from a web service. When you call the web service, you could pass the method to it so that when the web service responds, it call's the method you told it ... it "calls back".

In Java this can commonly be done through implementing an interface and passing an object (or an anonymous inner class) that implements it. You find this often with transactions and threading - such as the Futures API.

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Future.html

Also Refer to answers here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.