samedi 14 septembre 2019

How Can I Create method In Java With Same Type Parameter?

My code looks like below:

enum EnumType {
 CATEGORY,
 GROUP,
 MAIN
}

Methods:

public void call(EnumType type){
   switch(type):
     case CATEGORY:
        return methodForCategory();
     case GROUP:
        return methodForGroup();
     ...
}
public void methodForCategory(){
   ... Operations according to EnumType.CATEGORY
}
public void methodForGroup(){
   ... Operations according to EnumType.GROUP
}
public void methodForMain(){
   ... Operations according to EnumType.MAIN
}

But I want to call it without switch/case like below;

public void call(EnumType type){
    methodForType(EnumType type);
}

Is it possible or is there any better alternative?

Aucun commentaire:

Enregistrer un commentaire