Java polymorphism - how to call same method in different classes
问题 So I'm making a game in java, and I have objects all with the 2 methods; update() and render() . In my main class, where the game loop resides, I have to call both the update() and render() methods for every object that is updatable and renderable. Is there any way to set up some form of interface where I can call the methods once and it will call it in all implemented objects? 回答1: The other answers are correct, however it would be much better to use the composite pattern: public interface