java - Check enum for multiple values -
i have enum filetype
public static enum filetype { csv, xml, xls, txt, fixed_length } filetype filetype = filetype.csv;
is there better (cleaner) way check filetype
multiple values following (like "mystring".matches("a|b|c");
)?
if(filetype == filetype.csv || filetype == filetype.txt || filetype == filetype.fixed_length) {}
why not use switch
:
switch(filetype) { case csv: case txt: case fixed_length: dosomething(); break; }
this same if statement check, it's more readable, imho.
Comments
Post a Comment