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

Java Equivalent to VB 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:

VB Java
Public Class SomeType
    Private IntValue As Integer

    Public Shared Operator +(ByVal X As SomeType, ByVal Y As SomeType) As Integer
        Return X.IntValue + Y.IntValue
    End Operator

    Public Sub OperatorTest()
        Dim o As SomeType = Nothing
        Dim i As Integer = o + o
    End Sub
End Class
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 VB to Java Converter to convert from VB to Java.     


Copyright © 1997 – 2017 Tangible Software Solutions Inc.