• 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.

Overriding == in java... how?


The capability of allowing user defined operators is not part of the Java language defined by Sun Microsystems

however ...

you could use or write a preprocessor

jfront
 
ha, i was thinking the exact opposite when I started programming in C++, after having done extensive Java coding. As others have said, just use the CompareTo() function that is provided in java. Once you get used to java though, you'll never want to go back to C or C++, the garbage collector in Java is a godsend.
 
Originally posted by: notfred
What a peice of crap. How the hell does Java deterine if two objects are equivelent or not?
In Java, you use Object.equals() rather than the == operator for reference types. So the only question is if you need to override it (and also if you override Object.hashCode() as well).

For most of us, not being able to overload operators is not a big deal. The argument goes that operator overloading was more misused than useful.

As far as Sun is concerned, operator overloading is still not an important language feature. Other currently missing features have been deemed important enough for Java 1.5 (Tiger) though.
 
Originally posted by: manly
Originally posted by: notfred
What a peice of crap. How the hell does Java deterine if two objects are equivelent or not?
In Java, you use Object.equals() rather than the == operator for reference types. So the only question is if you need to override it (and also if you override Object.hashCode() as well).

For most of us, not being able to overload operators is not a big deal. The argument goes that operator overloading was more misused than useful.

As far as Sun is concerned, operator overloading is still not an important language feature. Other currently missing features have been deemed important enough for Java 1.5 (Tiger) though.

Although I appreciate that C# and C++ have op overloading, I agree with you. The use of op overloads in C++ always made things difficult to debug when a simple comparison operation threw an exception. I've always been of the opinion that being explicit is better than the taste of syntactic sugar, and abstracting yourself from such details is detrimental; they leak.

.NET does paint a prettier picture, however. C# supports op overloading, but VB.NET and friends do not. VB.NET can still call the emitted op overload methods: op_Addition for +, op_Subtraction for -, op_Equality for ==, etc. This is pretty absurd as it negates the syntactic sugar afforded by op overloading in the first place. Fortunately there are guidelines in place that help mitigate this a bit. In order to pass tests like FxCop for class libraries you have to provide a corresponding public method in place of the op overload: Add for +, Subtract for -, Equals for ==, etc..

Why do I always post a longer response than I anticipated?
 
Originally posted by: Descartes
Originally posted by: manly
Originally posted by: notfred
What a peice of crap. How the hell does Java deterine if two objects are equivelent or not?
In Java, you use Object.equals() rather than the == operator for reference types. So the only question is if you need to override it (and also if you override Object.hashCode() as well).

For most of us, not being able to overload operators is not a big deal. The argument goes that operator overloading was more misused than useful.

As far as Sun is concerned, operator overloading is still not an important language feature. Other currently missing features have been deemed important enough for Java 1.5 (Tiger) though.

Although I appreciate that C# and C++ have op overloading, I agree with you. The use of op overloads in C++ always made things difficult to debug when a simple comparison operation threw an exception. I've always been of the opinion that being explicit is better than the taste of syntactic sugar, and abstracting yourself from such details is detrimental; they leak.

.NET does paint a prettier picture, however. C# supports op overloading, but VB.NET and friends do not. VB.NET can still call the emitted op overload methods: op_Addition for +, op_Subtraction for -, op_Equality for ==, etc. This is pretty absurd as it negates the syntactic sugar afforded by op overloading in the first place. Fortunately there are guidelines in place that help mitigate this a bit. In order to pass tests like FxCop for class libraries you have to provide a corresponding public method in place of the op overload: Add for +, Subtract for -, Equals for ==, etc..

Why do I always post a longer response than I anticipated?

It's all that MS in your blood, things you make bloat up easily 😉 (seriously, joking, joking 😀)
 
Originally posted by: BingBongWongFooey
Originally posted by: Descartes
Originally posted by: manly
Originally posted by: notfred
What a peice of crap. How the hell does Java deterine if two objects are equivelent or not?
In Java, you use Object.equals() rather than the == operator for reference types. So the only question is if you need to override it (and also if you override Object.hashCode() as well).

For most of us, not being able to overload operators is not a big deal. The argument goes that operator overloading was more misused than useful.

As far as Sun is concerned, operator overloading is still not an important language feature. Other currently missing features have been deemed important enough for Java 1.5 (Tiger) though.

Although I appreciate that C# and C++ have op overloading, I agree with you. The use of op overloads in C++ always made things difficult to debug when a simple comparison operation threw an exception. I've always been of the opinion that being explicit is better than the taste of syntactic sugar, and abstracting yourself from such details is detrimental; they leak.

.NET does paint a prettier picture, however. C# supports op overloading, but VB.NET and friends do not. VB.NET can still call the emitted op overload methods: op_Addition for +, op_Subtraction for -, op_Equality for ==, etc. This is pretty absurd as it negates the syntactic sugar afforded by op overloading in the first place. Fortunately there are guidelines in place that help mitigate this a bit. In order to pass tests like FxCop for class libraries you have to provide a corresponding public method in place of the op overload: Add for +, Subtract for -, Equals for ==, etc..

Why do I always post a longer response than I anticipated?

It's all that MS in your blood, things you make bloat up easily 😉 (seriously, joking, joking 😀)

😀
 
Back
Top