Add name | Rename a java method using annotaion

461 Views Asked by At

I'm searching for a solution to get two name for one method using Java Annotation. I need something like this :

@SOMETHING(name="Method_Name_2")
public String methodName1(String arg){
    // Some code
    return var;
}

and when I call the method

obj.Method_Name_2(arg)

or

obj.methodName1(arg)

I need that the two call execute the same method.

1

There are 1 best solutions below

3
On

You cannot provide two different names for a method in java. However you can wrap original method inside new method name:

public String Method_Name_2(String arg){
    return methodName1(arg);
}