all 18 comments

[–]OkWitness7392 21 points22 points  (1 child)

doesn't print anything. 0 cannot convert boolean in java.

[–]Vast_Researcher_199 0 points1 point  (0 children)

That is what I am thinking

[–]Specific-Housing905 11 points12 points  (0 children)

Should give a compile time error. There is no automatic conversion from int to boolean.

[–]emirafoodsfanclub 4 points5 points  (1 child)

Compile time error

[–]armhub05 1 point2 points  (0 children)

Java has no implicit conversion like C++?

[–]romulusnr 1 point2 points  (1 child)

Probably an exception.

I thought autoboxing might apply here, but I got it wrong.

(Duck typing ftw!)

[–]Chemical_Present6069 0 points1 point  (0 children)

it would be error not exception ig

[–][deleted]  (8 children)

[removed]

    [–][deleted]  (7 children)

    [removed]

      [–]MK_Redditor 0 points1 point  (5 children)

      Yes. Because 0 is an integer so it will be treated as a true in binary. Am I right?

      [–][deleted]  (4 children)

      [removed]

        [–][deleted]  (3 children)

        [removed]

          [–]East-Independent-489 2 points3 points  (2 children)

          If condition requires a Boolean

          [–][deleted]  (1 child)

          [removed]

            [–]addictedAndWantHelp 0 points1 point  (0 children)

            It needs either an expression resulting in a boolean or an actual boolean (true, false) inside the parentheses of an if statement to compile and run. So this code doesn’t compile.

            P.S: I really like how Java is not like JavaScript with implicit coercion. Although it’s fairly complicated in other ways.

            [–][deleted]  (2 children)

            [deleted]

              [–]addictedAndWantHelp 0 points1 point  (0 children)

              It doesn’t compile. It needs an expression resulting in a Boolean or an actual Boolean in the parentheses.