• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unexpected type error on my && symbols!

 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a compile error of unexpected type with the arrows pointing to my "&&" symbols. I can't find the problem. Totally confused here. any suggestions would be appreciated.




 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I'm afraid this is not how you do an equality check. You would have to use the equality operator rather than the assignment operator. Pleas go through this link -> Equality operators
 
Marjorie Gyles
Ranch Hand
Posts: 42
Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh. Thanks. The message confused me on what was wrong.
 
Praveen Kumar M K
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The message was indeed right, in a different way

Unlike C and C++, Java enforces strict type checking extensively during compilation. Here the individual expressions of your if statement i.e., intentToGraduate = true and majorSheet = true
did not yield a boolean type with value "true" or "false" as they were assignment operations. Hence you got an unexpected type error.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better still, don't use = or == in that case. Let the boolean variables represent themselves directly:



That way you avoid the confusion entirely.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realize you're a beginner, so if what I'm about to say confuses you, then just put it aside for a while (or ignore it entirely). What I would do with that code is this:


(1) Don't need "== true"...

(2) Don't need an if-statement...

(3) Don't need a temporary variable...


You may find the end result hard to understand. That's completely normal, it takes a while to get used to boolean values, so if you find the original version easier to understand, stick with that for now.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic