aspose file tools*
The moose likes Beginning Java and the fly likes Unexpected type error on my && symbols! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unexpected type error on my && symbols!" Watch "Unexpected type error on my && symbols!" New topic
Author

Unexpected type error on my && symbols!

Marjorie Gyles
Ranch Hand

Joined: Nov 03, 2012
Posts: 42

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

Joined: Jul 03, 2011
Posts: 256


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

Joined: Nov 03, 2012
Posts: 42

Duh. Thanks. The message confused me on what was wrong.
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unexpected type error on my && symbols!