Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java

Started by HAM Nov 14, 2000 at 10:05 AM 4 replies 400+ views
Original Post
HAM
HAM
Sorry this is 100% a game devel question. Is it possible to overload operators in Java like it is in C++ Can I define how ''MyObject'' handles +,-,=,==,* etc... If Yes, How , i''ve looked through tons of docs can''t find it. Thanks for any info.
blckglass
blckglass
From what I know operator overloading is not possible. I have read almost all of the Java tutorial on Sun''s website and I didn''t see anything about, also in the couple books that I have read they don''t say anything about it. So I am pretty sure that I am correct.
felonius
felonius
No, you cannot.

The Java designers figured that operator overloading was misused to often, which often confused many people, so it wasn''t included. You may have another opinion (I know I have) but such is life.

The normal way to substitute this is to make methods with names like the operators, like this:

class Vector
{

...

public Vector add(Vector a)
{
...
}

...

}

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games
HAM
HAM
Thanks for the replies.


The answer sucks though. I like operator overloading.



felonius
felonius
>> the ability to add your own syntax

You might want to check out the language LISP. That language allows you to do this. You can actually redefine the full language within the language itself.

Jacob Marner

Edited by - felonius on November 15, 2000 4:24:58 AM
Jacob Marner, M.Sc.Console Programmer, Deadline Games

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.