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

Java Equivalent to VB Extension Methods

Java doesn't have extension methods, so a VB extension method is just converted to an ordinary Java static method (calls to the method have to be adjusted to static calls using the class name).

VB Java
Public Module ContainsExtension
    <System.Runtime.CompilerServices.Extension> _
    Public Sub ExtensionMethod(ByVal myParam As String)
        '...
    End Sub
End Module
Friend Class TestClass
    Private Sub TestMethod()
        Dim s As String
        s.ExtensionMethod()
    End Sub
End Class
public final class ContainsExtension
{
    public static void ExtensionMethod(String myParam)
    {
        //...
    }
}
public class TestClass
{
    private void TestMethod()
    {
        String s = null;
        ContainsExtension.ExtensionMethod(s);
    }
}


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


Copyright © 1997 – 2017 Tangible Software Solutions Inc.