Reputation: 135
I was searching for a shortcut to set same property function to multiple variables.
I am trying to achieve something like {var1, var2, var3}.setSomething(true)
and (var1, var2, var3).setSomething(true)
but it is not working. Is there anyway to get this done?
instead of
var1.setSomething(true)
var2.setSomething(true)
var3.setSomething(true)
How can I write all these in a same line or setting it only once?
Upvotes: 0
Views: 238
Reputation: 478
old school way, write a helper function:
public static void setSomeThing(boolean value, Target ... targets){
if(targets == null)
return;
for(Target target : targets){
target.setSomeThing(value);
}
}
for using:
setSomeThing(true,var1,var2,var3);
Upvotes: 4