简体   繁体   中英

Generically pass different parameters to the method

Lets assume I've two variables ;

Future<MyCustomObj1> mytask1 = <something 1>
Future<MyCustomObj2> mytask2 = <something 2 >

I want to cancel both tasks in case of any InterruptException,

so something like

mytask1.cancel(true);
mytask2.cancel(true);

instead of repeating it everywhere, I want to create a generic method which can take the Future task as argument and just call cancel.

public void cancelTasks(<fill here>) {
   <fill here>.cancel(true);
}

What should I substitute for <fill here> ?

Future<?> future

它的意思是“某种未知类型的Future ”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM