• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 307
  • Last Modified:

how to override operator in java?

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
eugeneng
Asked:
eugeneng
  • 3
  • 2
1 Solution
 
objectsCommented:
Operator overriding is not supported in Java.
0
 
eugenengAuthor Commented:
any other way to implement the same functionality?
0
 
objectsCommented:
not really, except of course to just use method names like lessThan etc.
0
 
eugenengAuthor Commented:
excellent!! thanx alot man..
0
 
objectsCommented:
Anytime, thanks for the points :)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now