Advertisement
_AMDG_

Speculation on goto in Java

Sep 4th, 2014
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. So I've been told the goto keyword is evil, but I don't know why. However I thought of a way it could be used. Remember that pastebin on Efficent Multi-Dimensional Collision Detection? Well I just got that idea. I'm not saying I would use goto for this, but its just a speculation.
  2.  
  3. Say you use that method of collision.
  4.  
  5. public Block collided(){/*code*/}
  6.  
  7. then in another method if that happens, it could be used as an observer pattern. Not just for this, but altogether as an observer pattern. if you wanted, it could be an alternative to constantly checking for if something happens, and it makes sense to use goto for this.
  8.  
  9. public void tick(){
  10.  
  11. __restart:
  12. collided();
  13. goto ifSomething;
  14. __ifSomething:
  15. if(something else happens)
  16. goto restart;
  17. }
  18.  
  19.  
  20. I use goto rather vaguely up above, but its just speculation you know. No harm in speculation. Now whatever you do, DO NOT COMPILE THIS: YOU WILL BE EATEN BY A VELOCIRAPTER.
  21.  
  22.  
  23. If only goto wasn't so evil...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement