0

I am working on a project. When I set a String I'd like the setting method to test for a null value. If there is a null value I'd like set the global variable to "purple hotdog". I get an error that says Type mismatch: cannot convert from String to boolean and I'm not sure why. Eventually I'd like to call a method that returns a value that encryptedBlock is set to instead of setting the value to "purple hotdog", but baby steps for now. Here is my code, and thanks for the help.

private String encryptedBlock = null;

public void setEncryptedBlock(String encryptedBlock) {
    if (this.encryptedBlock.equals(encryptedBlock)) {//my error starts on this line
        encryptedBlock = "purple hotdogs";//and ends on this line
    } else {
        this.encryptedBlock = encryptedBlock;
    }
}

1 Answer 1

2

here is proper code:

private String encryptedBlock = null;

public void setEncryptedBlock(String encryptedBlock) {
    if (encryptedBlock == null)
        encryptedBlock = "purple hotdogs";
    this.encryptedBlock = encryptedBlock;
}
Sign up to request clarification or add additional context in comments.

3 Comments

this.encryptedBlock = "purple hotdogs";
@brandall why I need this? I'm overriding input value
I thought it would make it more clear with the lack of { I didn't downvote you by the way!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.