Solved

how to override operator in java?

Posted on 2001-08-01
5
274 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

758 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

22 Experts available now in Live!

Get 1:1 Help Now