vendredi 3 décembre 2021

Java boolean "Unexpected return value"

I'm new to Java and I can't understand why the IDE says that "Unexpected return value" inside the forEach where I declared that the boolean is true or false by an If statement. My goal is to check that there is an object inside the "States" HashMap which already uses the name that I want to set to a new state. (The HashMap's key is a String which is called IdentifierOfState and the value is my State object which contains variables like its name.) Thank you for your help in advance!

public boolean isStateNameClaimed(String NameOfState)
{
    States.forEach((IdentifierOfState, ValueOfState) ->
    {
        if (ValueOfState.getNameOfState().equalsIgnoreCase(NameOfState)) {return true;}
        else {return false;}
    });
    return false;
}

Aucun commentaire:

Enregistrer un commentaire