Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point of exit from a method in Java

In Eclipse, is there any way to find which return statement a method returned from without logging flags at every return statment?

For example:

@Override
 public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof ABC)) {
        return false;
    }
    ABC other = (ABC) obj;
    if (var1 == null) {
        if (other.var1 != null) {
            return false;
        }
    } else if (!var1.equals(other.var1)) {
        return false;
    }
    return true;
}

In this case, how do I find out at which point my equals method returned?

like image 579
FirstName LastName Avatar asked Mar 07 '13 23:03

FirstName LastName


2 Answers

No, but a more understandable and debug friendly code can be with a boolean local variable that represents the result.

then you can see with debugger who assign it when and the return value before returned.

like image 53
Chen Kinnrot Avatar answered Sep 21 '22 17:09

Chen Kinnrot


No. This is one reason that some people prefer single point of exit: Why should a function have only one exit-point?

Note also the links in the first comment on that question.

like image 35
Cory Kendall Avatar answered Sep 18 '22 17:09

Cory Kendall