java - Callable<Void> as Functional Interface with lambdas -
i learning new java8 features. , here question:
why not allowed utilize callable<void> functional interface lambda expressions? (compiler complains returning value) , still legal utilize callable<integer> there. here sample code:
public class test { public static void main(string[] args) throws exception { // works fine testint(() -> { system.out.println("from testint method"); homecoming 1; }); testvoid(() -> { system.out.println("from testvoid method"); // error! can't homecoming void? }); } public static void testint(callable<integer> callable) throws exception { callable.call(); } public static void testvoid(callable<void> callable) throws exception { callable.call(); } } how explain behavior?
for void method (different void method), have homecoming null.
void placeholder stating don't have homecoming value (even though build -- callable here -- needs one). compiler not treat in special way, still have set in "normal" homecoming statement yourself.
java lambda java-8 void callable
No comments:
Post a Comment