java - EnumSet from array, shortest variant? -


i need enumset array (which given through varargs method parameter). first, surprised there no varargs constructor method in enumset (there enumset#of(e first, e... rest)). workaround, used following variant:

enumset<options> temp = enumset.copyof(arrays.aslist(options)); 

however, triggers java.lang.illegalargumentexception: collection empty. so, ended following, looks ridiculous:

enumset<options> temp = options.length > 0 ?                          enumset.copyof(arrays.aslist(options)) :                          enumset.noneof(options.class); 

if course moved utility method, still, i'm asking myself if there simpler way using existing methods?

this 2 lines, less complex:

    enumset<options> temp = enumset.noneof(options.class); // make empty enumset     temp.addall(arrays.aslist(options)); // add varargs 

i don't consider worse other kind of variable declaration class doesn't have constructor want:

    someclass variable = new someclass(); // make empty object     variable.addstuff(stuff); // add stuff 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -