Java - Can enum in a parameter of an abstract method -
i not familiar enum , want ask whether can put enum in abstract method , override in other class? here example working with:
i have many subclasses extend abstract class, each have own sub command enum type. enum type has int id , string name.
also, method takes sub command , change input ui base on selected sub command.
public class commandone extends commandclass{ ........ public void updateuibysubcmd(subcommand subcmd){ /*do something*/ } private enum subcommand{ subcmd1 (id1, name1), subcmd2 (id2, name2), ........ } }
i have abstract class extended above subclass, not consist enum couple function override subclass.
the question is, can following , have method updateuibysubcmd become abstract enum type? if allowed, how accomplish it?
public abstract class commandclass{ .......... public abstract void updateuibysubcmd(enum x); }
sounds you're looking this:
public abstract class commandclass<e extends enum<e>> { .......... public abstract void updateuibysubcmd(e x); } public class commandone extends commandclass<subcommand> { ........ @override public void updateuibysubcmd(subcommand subcmd){ /*do something*/ } } public enum subcommand { subcmd1 (id1, name1), subcmd2 (id2, name2), ........ }
Comments
Post a Comment