d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Java Compiler Bug?
12Next
Add Reply New Topic New Poll
Member
Posts: 34,575
Joined: Mar 25 2009
Gold: 12,633.00
Jun 18 2016 01:11pm
http://pastebin.com/5SUPUcqs

if (a ! true)

^should work, but doesn't compile
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 18 2016 01:12pm
Quote (ferf @ Jun 18 2016 03:11pm)
http://pastebin.com/5SUPUcqs

if (a ! true)

^should work, but doesn't compile


what makes you think it should work? it looks like a compile error to me.

! is a unary operator, meaning it only has one operand to the right. however, you have two operands there. so something isn't right.

it converts into:

Code
if (true ! true)

then:
Code
if (true false)


does that look good to you?

the if keyword requires an expression to return a single boolean value.

99% of the time you think the compiler is wrong is actually user error.

This post was edited by carteblanche on Jun 18 2016 01:16pm
Member
Posts: 34,575
Joined: Mar 25 2009
Gold: 12,633.00
Jun 18 2016 01:13pm
Quote (carteblanche @ Jun 18 2016 03:12pm)
what makes you think it should work? it looks like a compile error to me.


hmm ok
Member
Posts: 34,575
Joined: Mar 25 2009
Gold: 12,633.00
Jun 18 2016 01:17pm
Quote (carteblanche @ Jun 18 2016 03:12pm)
what makes you think it should work? it looks like a compile error to me.

! is a unary operator, meaning it only has one operand to the right. however, you have two operands there. so something isn't right.

it converts into:

Code
if (true ! true)

then:
Code
if (true false)


does that look good to you?

the if keyword requires an expression to return a single boolean value.


Yeah i knew it was unary which was why i didn't think it'd work, but my friend said otherwise haha
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 18 2016 02:03pm
You are looking for

Code
if(a != true)
Member
Posts: 34,575
Joined: Mar 25 2009
Gold: 12,633.00
Jun 18 2016 02:42pm
Quote (AbDuCt @ Jun 18 2016 04:03pm)
You are looking for

Code
if(a != true)


word, makes sense :P
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Jun 19 2016 08:55am
what you're actually looking for is

if (!a)
Member
Posts: 23,444
Joined: Jun 30 2009
Gold: 167.53
Jun 19 2016 09:27am
I am curious why people are posting the code without the error that is thrown in the console?
the error is just as important as the code lol. I know its simple code but its always a good habit to post the error with the code.

This post was edited by umeshieee on Jun 19 2016 09:30am
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Jun 19 2016 11:10am
Quote (Ideophobe @ Jun 19 2016 10:55am)
what you're actually looking for is

if (!a)


I hope you realize `!a' and `a != true' equate to the same thing. There is no actuality for what they may be looking for.

What you're actually looking for is

if(!!!!a != !!true)

or

if(a^a)

or

if(!(a^a) != !!!(true^true))

Although due note that these equations are purely for sport and remember that anything xor itself will always be 0, thus they hold no logical meaning.

This post was edited by AbDuCt on Jun 19 2016 11:13am
Member
Posts: 14,631
Joined: Sep 14 2006
Gold: 575.56
Jun 19 2016 05:16pm
dude said he was told he could use it as a unary operator
besides being redundant i think it's just an ugly thing to do writing equality comparisons for booleans
they should be named things like isAvailable, isContainedInGpsList, isWhatever so when you look at if statements it's just obvious you're checking whether something is true or not
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll