• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java has a broken = operator?

I was reading about Ceylon, a new language being developed by Red Hat. In the presentation slides (pdf) one of the frustrations he mentions with Java is the "broken = operator".

What does he mean by this? Google turned up nothing. Do you think it's a typo and should say "broken == operator"? I can kind of understand that because == really traps a lot of junior Java devs, but I can't think of any issues with assignment.

Ideas?
 
Let me contrive a situation for you:

Code:
String a = "nef";
String b = "neffer";
b = b.substring(0,3);

Now, does a == b? No! Because they're different pointers. What is true is that a.equals(b).

I guess he wants operator overloading on ==.

Edit: Oh, you do mean =. 😕
 
Last edited:
Let me contrive a situation for you:

Code:
String a = "nef";
String b = "neffer";
b = b.substring(0,3);

Now, does a == b? No! Because they're different pointers. What is true is that a.equals(b).

I guess he wants operator overloading on ==.
Yeah that's what I meant when I said == may be considered broken. I guess it's just two ways of looking at the same thing, but to me the assignment operator is working just fine.
 
I kind of agree with the arstechnica article. Do we really need yet another language?
So this isn't a brand new language, but an addon to java. still, there's tons of languages out there today. Do we need another?
 
So this isn't a brand new language, but an addon to java. still, there's tons of languages out there today. Do we need another?
No, it's an entirely new language. It just runs on the JVM.

I'm kind of a languages geek so I like seeing what's happening with new languages, but yeah we probably don't need yet another general-purpose OO language.
 
After reviewing the talk, my guess is that they meant "operator =", as written. The talk seems to gripe about a lot of stuff in Java that isn't broken (e.g., "you can't create a good user interface in Java", synchronized keyword, etc.).

And, IMO, this "Ceylon" language smacks of a language with nothing going for it at all.
 
I'm not a Java guy, but my hunch would be that, as in a number of languages, the following would evaluate to true:

Code:
if (a = 5) { ... }

Whether this is "broken" is of course a matter of opinion; it's often not what you expect, but it can be useful.
 
I'm not a Java guy, but my hunch would be that, as in a number of languages, the following would evaluate to true:

Code:
if (a = 5) { ... }

Whether this is "broken" is of course a matter of opinion; it's often not what you expect, but it can be useful.
If you're not a Java guy you would do well to stay away from Java threads. Someone might read this nonsense and actually believe it. This is NOT THE CASE in Java, in fact this won't even compile in Java.
 
If you're not a Java guy you would do well to stay away from Java threads. Someone might read this nonsense and actually believe it. This is NOT THE CASE in Java, in fact this won't even compile in Java.

I am sincerely curious if you realize how disproportionate your anger is to this situation.

You mean allowing assignment in an 'if'? Java will allow it but you must use booleans (no implicit conversion from ints to bools).

So doing the same thing but instead assigning true to a boolean would work? Or am I misinterpreting you?
 
So doing the same thing but instead assigning true to a boolean would work? Or am I misinterpreting you?


Ex:
Code:
while(1) {} // Will Not Compile

while(true) {} // Will Compile

So I was meaning that your example would have to be something like:

Code:
boolean b = false;

if (b=true) {
    // Always will execute
} else {
    // Never will execute
}

So yes Java does have assignment expressions, however I think that's a different debate from the functionality of the assignment operator.
 
Last edited:
A clue to what he is saying may be found on page 21 of his presentation.

Assignment to a variable value or attribute setter is done using the := operator. The specifier is used only for specifying immutable values.


immutable values are the C++ equivolent to a const value. I dont understand why he needs a different operator for const vs non-const values, as that is a property of the variable not the oeprator.
 
Back
Top