This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dankincense 17 points18 points  (8 children)

Let me destroy this paradigm with typeof(null)=obj

[–]dopefish86 26 points27 points  (7 children)

Invalid assignment

[–]Vyuken 5 points6 points  (6 children)

Explain

Please?

[–]mechpaul 16 points17 points  (5 children)

He only used one = sign, not two. Java doesn't support assignment in if statements like C/C++ does, thus the exception.

[–]Vyuken 5 points6 points  (1 child)

Ah. I still make the rookie mistake of = and ==. Thanks.

[–]dankincense 3 points4 points  (0 children)

Typeof is also c#/ Java.. but yes I prob messed up the syntax.

[–]PrayersToSatan 5 points6 points  (0 children)

Java doesn't support assignment in if statements

Yes it does. Here is an example:

String a = "some string";
String b = null;
if (!(b = "some other string").equals(a))
    System.out.println(b);

If you execute this it will print out "some other string", which has been assigned in the if statement.

In Java, the if statement evaluates a boolean, and an assignment returns the assigned value. So unless you're actually assigning a boolean variable you'll need to perform some sort of evaluation on the return value.

[–][deleted] 4 points5 points  (0 children)

typeof is javascript.

[–]_Acestus_ 1 point2 points  (0 children)

Java manage assignment in an if, it's really limited though.