0

I'm stuct at if with string, error calls like this:

Unreachable statement, comaparing strings with == or !=

Tried equals also, but calls same error here, any help please?

public boolean register(int hwork, String album) {
    hwork=6;
    album="116614";
    throw new UnsupportedOperationException();
    if(album=="166614")
        return true;
    else
        return false;
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • don't use `==` for string comparisons – Ramanlfc Dec 05 '15 at 08:55
  • 1
    The `UnsupportedOperationException` exception you are throwing will make it impossible to reach the code underneath. Usually you'd want it to signal a situation where your code cannot proceed without error handling or logging. Meaning you check for some error state using an if-statement and then throw an exception. You also used `==` for string comparison. You should use the equals method of the string instead. Finally the if-statement and return statements can be reduced to simply `return album.equals("166614")`. – André C. Andersen Dec 05 '15 at 09:05
  • I have reverted your edit, when you make change, don't fix the problem that were the original cause to ask the question. It will invalidate any existing answers, and those answers (and comments) look out of place. Instead accept the answer that solved your problem and/or post a comment or a substantial answer to let others know the problem was solved (and how). – Mark Rotteveel Dec 05 '15 at 09:14

1 Answers1

1
throw new UnsupportedOperationException();
if(album=="166614")
return true;
else
return false;
}

the compiler can see that you are throwing an exception. so execution of the method won't go any further

Ramanlfc
  • 8,283
  • 1
  • 18
  • 24