Improving readability of type/casting error messages

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Dec 5 17:56:58 UTC 2014


On 05/12/14 02:05, cowwoc wrote:
> I'll start by discussing a seemingly benign error message:
>
> incompatible types: bad return type in lambda expression
>      Promise<Optional<GetPostalCode>> cannot be converted to Optional
Hi Gili,
are you sure you are pasting the entire output? Or maybe something more 
subtle is going on? Look at this example:

import java.util.function.*;
import java.util.*;

class Test {
     void test() {
         m(ls -> ls);
     }

     void m(Function<List<String>, List<Integer>> l) { }
}


Which gives this:

Main.java:6: error: incompatible types: bad return type in lambda expression
         m(ls -> ls);
                 ^
     List<String> cannot be converted to List<Integer>

Note that both actual and expected type are shown after type 
substitution. I don't exactly get why you are getting a bare 'Option' in 
your example - is some unchecked conversion going on?

Maurizio


More information about the compiler-dev mailing list