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

Java Equivalent to C# Extension Methods

Java doesn't have extension methods, so a C# 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).

C# Java
public static class ContainsExtension
{
    public static void ExtensionMethod(this string myParam)
    {
        //...
    }
}
class TestClass
{
    void TestMethod()
    {
        string s;
        s.ExtensionMethod();
    }
}
public final class ContainsExtension
{
    public static void ExtensionMethod(String myParam)
    {
        //...
    }
}
public class TestClass
{
    private void TestMethod()
    {
        String s;
        ContainsExtension.ExtensionMethod(s);
    }
}


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

Additional resource: Java and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.