I fixed an endless loop by changing Integer to int in the following:
public class IntTest { public static void main(String[] args) { Integer x=-1
Integer is an Object, and objects are compared with .equals(..)
Integer
Object
.equals(..)
Only primitives are compared with ==
==
That's the rule, apart from some exceptional cases, where == can be used for comparing objects. But even then it is not advisable.