Question about type inference.
Denis DEBARBIEUX
denis.debarbieux at inria.fr
Wed Dec 26 04:13:43 PST 2012
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
//
--
Denis Debarbieux
Engineer at INRIA
+33 (0)3.59.35.87.10
Skype: denis.debarbieux
More information about the lambda-dev
mailing list