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

Java Equivalent to C# Operator Overloading

Most programming languages allow 'overloading' operators to implement specialized behavior for the operator when used on instance of a type. Java doesn't allow this, but the same behavior is achieved through method calls:

C# Java
public class SomeType
{
    private int IntValue;

    public static int operator +(SomeType X, SomeType Y)
    {
        return X.IntValue + Y.IntValue;
    }

    public void OperatorTest()
    {
        SomeType o = null;
        int i = o + o;
    }
}
public class SomeType
{
    private int IntValue;

    public static int OpAddition(SomeType X, SomeType Y)
    {
        return X.IntValue + Y.IntValue;
    }

    public final void OperatorTest()
    {
        SomeType o = null;
        int i = SomeType.OpAddition(o, o);
    }
}


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

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.