0

i'm trying to make a simple code and this point in the code generates an error in the script saying String can't be used as boolean even though i'm not using it as boolean

String wc = Mt.input("asks for input") /*i have a class called Mt that basically just makes writing lines and asking for input easier*/ 
if (wc = "a possible input for wc") {//error occurs here
    Mt.s("words");
    Mt.input("");
    System.exit(0);
}

the error is

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Type mismatch: cannot convert from String to boolean

    at Main.main(Main.java:20)//line of if statement in full code
yanzinator
  • 17
  • 7
  • 2
    1. `=` is assignment, `==` is equality. 2. Use `compare()` for Strings and all other objects – PM 77-1 Jan 30 '20 at 00:20
  • 1
    in addition to above, comparing Strings with `==` is true only when both Strings points to the same memory location. Getting String from any input will have different memory location than the hardcoded one. Use `"a possible inut for wc".equals(wc)` instead. – itwasntme Jan 30 '20 at 00:24

0 Answers0