BEN YOUSSEF Hamza
BEN YOUSSEF Hamza

Reputation: 27

Add name | Rename a java method using annotaion

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.

Upvotes: 1

Views: 467

Answers (1)

Sarit Adhikari
Sarit Adhikari

Reputation: 1402

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);
}

Upvotes: 3

Related Questions