Question about type inference.

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Thu Dec 27 03:10:49 PST 2012


We are working on improvements that will make code like this to work.

Maurizio

On 26/12/12 12:13, Denis DEBARBIEUX wrote:
> Hi all,
>
> I'm trying to run examples with type inference.
>
> The following example fails:
>
> public class Main{
> /
> //public static void main(String[] args) {//
> //	System.out.println("start");//
> //	Set<List<String>> stream = getStream();		//
> //	stream.stream().filter(set -> set.size() == 0).forEach(System.out::println);//
> //	System.out.println("end");//
> //}//
> //
> //private static Set<List<String>> getStream() {//
> //	Set<List<String>> stream = new HashSet<>();//
> //	add(stream, Collections.emptyList()); // fail//
> //	// Main.<List<String>>add(stream, Collections.emptyList()); // OK		//
> //	return Collections.unmodifiableSet(stream);//
> //}//
> //	//
> //private static <T> void add(Set<T> set, T element) {//
> //	set.add(element);//
> //}//
> //
> }
>
> //lambda-8-b69-windows-i586-17_dec_2012/jdk1.8.0/bin/javac test/Main.java//
> //test\Main.java:34: error: method add in class Main cannot be applied to given types;//
> //                  add(stream, Collections.emptyList()); // fail//
> //                  ^//
> //   required: Set<T>,T//
> //   found: Set<List<String>>,List<Object>//
> //   reason: inferred type does not conform to lower bound(s)//
> //     inferred: List<String>//
> //     lower bound(s): List<Object>//
> //   where T is a type-variable://
> //     T extends Object declared in method <T>add(Set<T>,T)//
> //1 error/
>
> Is this supposed to work ?
>
>
> Thanks
>
> Denis
>
> //
>



More information about the lambda-dev mailing list