Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to override operator in java?

Posted on 2001-08-01
5
Medium Priority
?
304 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

636 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