0

I have a number of setter methods which take an enum. These are based on incoming objects attribute. Rather than write a bunch of these is there a way around having to hard code say 10 different case statements. Would there be a way to create a reusable method?

//Side class declared as
public final enum Side

//How I initialise side
static Side side = Side.SELL;//default

//method to set object
Obj.setSide(sideEnum(zasAlloc.getM_buySellCode()));

//How I am implementing it
    public static Side sideEnum(String buysell)
    {

        if(buysell.equalsIgnoreCase("S"))
        {
            side = Side.SELL; //default 
        }
        else if(buysell.equalsIgnoreCase("B"))
        {
            side = Side.BUY; 
        }

        return side;

    }
0

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.