• Saves Valuable Time
  • Trusted Accuracy since 2004
  • 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 opAdd(SomeType X, SomeType Y)
        return X.IntValue + Y.IntValue;

    public final void OperatorTest()
        SomeType o = null;
        int i = SomeType.opAdd(o, o);

Use VB to Java Converter to convert from VB to Java.     

Additional resource: VB.NET and Java Equivalents

Copyright © 2004 – 2021 Tangible Software Solutions, Inc.