[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Java

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 5

File: nier oh no.jpg (18KB, 240x233px) Image search: [Google]
nier oh no.jpg
18KB, 240x233px
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
>>
File: 636536465436.jpg (23KB, 273x457px) Image search: [Google]
636536465436.jpg
23KB, 273x457px
>>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");
>>
File: mathsinjava.jpg (57KB, 674x490px) Image search: [Google]
mathsinjava.jpg
57KB, 674x490px
>>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
>>
File: 1482512783510.jpg (55KB, 640x480px) Image search: [Google]
1482512783510.jpg
55KB, 640x480px
>>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.
Thread posts: 17
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.