Solved

how to override operator in java?

Posted on 2001-08-01
5
284 Views
Last Modified: 2012-05-07
hi, I'm a C++ program and new in Java, how can I override the operators (==,+=,=,-= etc) in Java ? For example in c++ we do :

Class Test
{
   int value;
   Test()
   {
     value= 0;
   };
   
  const Test& operator =(Test t)
  {
    this->value = t.value;
  }
  bool operator ==(Test t)
  {
    return this->value == t.value;
  }
}

how to do this in Java?
0
Comment
Question by:eugeneng
  • 3
  • 2
5 Comments
 
LVL 92

Expert Comment

by:objects
ID: 6343189
Operator overriding is not supported in Java.
0
 

Author Comment

by:eugeneng
ID: 6343231
any other way to implement the same functionality?
0
 
LVL 92

Accepted Solution

by:
objects earned 30 total points
ID: 6343356
not really, except of course to just use method names like lessThan etc.
0
 

Author Comment

by:eugeneng
ID: 6343490
excellent!! thanx alot man..
0
 
LVL 92

Expert Comment

by:objects
ID: 6343798
Anytime, thanks for the points :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
diffSum example 4 50
swing controls 2 16
web project error add remove 1 28
maven not picking latest jar instead picking old jar from .m2 12 18
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question