Monday, April 14, 2008

EnumSet from VarArgs

Irritating that EnumSet doesn't support Varargs and/or iterable. That means you need some ugly transition code like:


public InclusionCompletionModel(JobStatus... completeStatuses) {
this.completeStatuses = EnumSet.copyOf( Arrays.asList( completeStatuses ) );
}

2 comments:

Unknown said...

Sure it does.

How about:

if (completeStatuses.length > 0) {
this.completeStatuses = EnumSet.of(completeStatuses[0], completeStatuses);
} else {
this.completeStatuses = EnumSet.noneOf(InclusionCompletionModel.class);
}

Geoffrey Wiseman said...

Aren't you just proving my point about ugly transitional code? :)