• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

Java Equivalent to C++ Operator Overloading

Java doesn't offer operator overloading, so you have to create 'regular' methods in the place of operator overloads:

C++ Java
class SomeType
{
private:
    int IntValue = 0;

public:
    int operator + (const SomeType &Y)
    {
        return this->IntValue + Y.IntValue;
    }
};
public class SomeType
{
private int IntValue = 0;

    public int add (SomeType Y)
    {
        return this.IntValue + Y.IntValue;
    }
}


Use C++ to Java Converter to convert from C++ to Java.     

Additional resource: Java and C++ Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.