Reputation: 137
I was wondering if I can convert the following into a if statement rather than it being a switch statement.
switch (type) {
case PROJECT:
case STORY:
case DEVELOPER:
createdItem = new AggregateItem(name, desc, value);
break;
case STORY_DEVELOPER:
createdItem = new SingleItem(name, value, child);
break;
default:
createdItem = null;
}
Upvotes: 1
Views: 64
Reputation: 12523
concatinate the first three switch cases
with or
.
Then it follows an else if
and last but not least the else
.
if(PROJECT.equals(type)|| STORY.equals(type) || STORY.equals(DEVELOPER)){
createdItem = new AggregateItem(name, desc, value);
}else if (STORY_DEVELOPER.equals(type)){
createdItem = new SingleItem(name, value, child);
}else{
createdItem = null;
}
Upvotes: 4