More Typing Problems

Rémi Forax forax at univ-mlv.fr
Tue Sep 7 02:13:52 PDT 2010


Le 06/09/2010 23:39, Ming-Yee Iu a écrit :
> I'm having more problems with getting my code to type properly. The
> following piece of code does not compile due to typing problems:
>    

Hi,
you forget to put wildcards in you code

>
> public class Test
> {
>     public static class Customer {
>        public String getName() { return "";}
>     }
>     public abstract static class StringSorter<U>  {
>        abstract String value(U val);
>     }
>     public static interface Select<U, V>  {
>        public V select(U val);
>     }
>     public static class DBSet<T>   {
>        public<U>  DBSet<U>  select(Select<T,U>  x) {return new DBSet<U>();}
>    

should be <U> DBSet<U> select(Select<? super T,? extends U> x)
>        public DBSet<T>  sortedByStringAscending(StringSorter<T>  x) {return this;}
>    

should be DBSet<T> sortedByStringAscending(StringSorter<? super T> x)
>     }
>
>     public static DBSet<Customer>  allCustomer()
>     {
>        return new DBSet<Customer>();
>     }
>
>     public static void main(String[] args)
>     {
>        DBSet<String>  result = allCustomer()
>           .select(#(c){c.getName()})
> //; result = result    // if you uncomment this line, then it compiles fine
>           .sortedByStringAscending(#(str){str});
>     }
> }
>
> But if I uncomment the 4th line from the bottom, it then compiles fine.
>
> -Ming
>    

Rémi


More information about the lambda-dev mailing list