Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the error "should check the method return value" mean?

Tags:

java

swing

I am writing an application in Java using Swing. I am trying to convert the value in the text field txtDay to uppercase before evaluating the value in the below switch statement.

txtDay.getText().toUpperCase();

switch(txtDay.getText()){
    case "SUNDAY":
        //do something
        break;
    case "MONDAY":
        //do something
        break;
    case "TUESDAY":
        //do something
        break;
    case "WEDNESDAY":
        //do something
        break;
    case "THURSDAY":
        //do something
        break;
    case "FRIDAY":
        //do something
        break;
    case "SATURDAY":
        //do something
        break;
    default:
        //do something
        break;
}

Though at the first line (txtDay.getText().toUpperCase()), I am receiving an error saying "Should check the method return value".

What does this mean? Any tips on how to resolve this?

like image 679
Jaxon Crosmas Avatar asked Oct 15 '25 14:10

Jaxon Crosmas


1 Answers

It's not an error but a warning. It says that you are not using the result of the operation. Strings being immutable, you need something like:

txtDay.setText(txtDay.getText().toUpperCase());

to get the result you expect.

like image 171
assylias Avatar answered Oct 18 '25 05:10

assylias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!