how to override operator in java?

Posted on 2001-08-01
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;
     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?
Question by:eugeneng
  • 3
  • 2
LVL 92

Expert Comment

ID: 6343189
Operator overriding is not supported in Java.

Author Comment

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

Accepted Solution

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

Author Comment

ID: 6343490
excellent!! thanx alot man..
LVL 92

Expert Comment

ID: 6343798
Anytime, thanks for the points :)

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python Assistance 7 71
servlet doXXX methods 3 33
table example 4 19
varialbe initialization 11 30
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now