java - Can the Enum TimeUnit be passed as an argument to a method? -
java - Can the Enum TimeUnit be passed as an argument to a method? -
is possible enum timeunit passed argument method? writing java method takes long duration argument , curious if there improve way it. basically, want pass method little bit clearer/explicit on duration trying pass it. don't want write own wrapper since sure exists out there, doesn't it?
so, this, doesn't work because unit doesn't store "state", it? :
void timedmethod( timeunit unit ) { long duration = 1000; long val = unit.tomillis(duration); }
yes of course. illustration 1 of signatures of future#get
is:
public v get(long timeout, timeunit unit);
and implementation looks like:
long millis = unit.tomillis(timeout); //do number of milliseconds
so if phone call get(1, seconds)
, millis
1000.
java enums
Comments
Post a Comment