java - Submit task which implements a subinterface of Callable<T> to an ExecutorService -
how submit task implements subinterface of callable<t> executorservice?
i have subinterface of callable<t> defined as:
public interface ctigwtask<t> extends callable { ... } it defines static constants adds no methods.
then have following method execservice fixedthreadpool instance.
@override public ctigwtaskresult<integer> postctitask(ctigwtask<ctigwtaskresult<integer>> task) { future<ctigwtaskresult<integer>> result = execservice.submit(task); try { return result.get(); } catch (interruptedexception | executionexception ex) { logger.log(level.finest, "could not complete ctigwtask", ex); return new ctigwtaskresult<>( ctigwresultconstants.ctigw_server_shuttingdown_error, boolean.false, "cannot complete task: ctigateway server shutting down.", ex); } } unfortunately giving 2 unchecked conversion , 1 unchecked method invocation warnings.
...\ctigwworkerimpl.java:151: warning: [unchecked] unchecked conversion execservice.submit(task); required: callable<t> found: ctigwtask<ctigwtaskresult<integer>> t type-variable: t extends object declared in method <t>submit(callable<t>) ...\ctigwworkerimpl.java:151: warning: [unchecked] unchecked method invocation: method submit in interface executorservice applied given types execservice.submit(task); required: callable<t> found: ctigwtask<ctigwtaskresult<integer>> t type-variable: t extends object declared in method <t>submit(callable<t>) ...\ctigwworkerimpl.java:151: warning: [unchecked] unchecked conversion execservice.submit(task); required: future<ctigwtaskresult<integer>> found: future if change submit call to
future<ctigwtaskresult<integer>> result = execservice.submit( (callable<ctigwtaskresult<integer>>) task); then seems work unchecked cast warning.
...\src\com\dafquest\ctigw\cucm\ctigwworkerimpl.java:151: warning: [unchecked] unchecked cast execservice.submit((callable<ctigwtaskresult<integer>>) task); required: callable<ctigwtaskresult<integer>> found: ctigwtask<ctigwtaskresult<integer>> so i'm missing? shouldn't submit() apply instance of subclass of callable?
you using raw callable type.
change:
public interface ctigwtask<t> extends callable to this:
public interface ctigwtask<t> extends callable<t>
Comments
Post a Comment