Search code examples
javaintellij-idealambda

Java "target type of lambda conversion must be an interface"


I'm trying to use lambdas and streams in java but I'm quite new to it. I got this error in IntelliJ "target type of lambda conversion must be an interface" when I try to make a lambda expression

List<Callable<SomeClass>> callList = prgll.stream()
                                          .map(p->(()->{return p.funct();} )) <--- Here I get error
                                          .collect(Collectors.toList());

Am I doing something wrong?


Solution

  • I suspect it's just Java's type inference not being quite smart enough. Try

     .map(p -> (Callable<SomeClass>) () -> p.funct())