int a=2, b=4;
if(Boolean.toString(a==b).equals("true"))
{
System.out.println("it worked");
}
>prints nothing to console
>change b to 2
>prints to console "it worked"
fuck me, why the hell does this work
why wouldn't it?
2==2 yields the Boolean true
Boolean.toString(true) yields "true"
"true" equals "true" yields true
if(true) will execute the block.
right?
can you explain what you think should happen?
>>61149193
java is the most unforgiving strict language out there, but it accepts this.
really now.
not to mention the -10 which is also accepted.
>>61149167
2 == 2 is true
true to string is true
So it seems alright
>>61149167
Is this homework or are you a dumbass
>>61149229
Why the fuck wouldn't it accept "true".equals("true") as true?
>>61149244
"true" is not an object as apposed to
String comp="true";
if(comp.equals("true")){
syso("true");
}
>>61149453
Try
System.out.println("true".equals("true"));
>>61149229
You can write equivalent code even in Haskell. Few languages prevent programmers from writing correct but stupid code.
>>61149167
>Boolean.toString(a==b).equals("true")
dude what
Are you being intentionally dense
>>61149167
If this was for testing Java's quirks, I get it. If not, the boolean and String operations are completely unnecessary.
int a=2, b=4;
if(a==b)
System.out.println("it worked");
>>61149167
>>61149453
>"true" is not an object
Bullshit. It's a string. Strings are not primitives in Java, they are objects.
>>61149167
why wouldn't it work? looks perfectly reasonable
>>61149167
>>61152286
It's actually an object in the string literal pool, it's cached. Not that it matters in this case. I still don't get OP's confusion with the snippet.