Captured wildcards
    Maurizio Cimadamore 
    maurizio.cimadamore at oracle.com
       
    Thu Mar 19 12:22:49 UTC 2015
    
    
  
Upper bound should always be used - although I'm not 100% sure of what 
should happen when an upper bound is an intersection type:
interface A { }
interface B { }
class E implements A, B { }
class Foo<X extends A & B> {
     X x;
     Foo(X x) {
         this.x = x;
     }
     X get() {
         return x;
     }
}
Foo<?> foo = new Foo<>(new E());
foo.get(); //???
Maurizio
On 19/03/15 11:28, Jan Lahoda wrote:
> Hello,
>
> Assume this declaration:
> List<? extends String> list = Arrays.asList("a");
>
> This expression fails:
> -> list.iterator().next()
> |  Error:
> |  illegal start of type
> |  list.iterator().next()
> |  ^
>
> The reason is that "? extends String" is used as the type of the 
> expression, instead of "String":
> ---
> package REPL;
> import java.util.regex.*;import java.util.*;import 
> java.util.concurrent.*;import java.util.prefs.*;import 
> java.net.*;import java.io.*;import java.math.*;import static 
> REPL.$REPL8.printf;
> import static REPL.$REPL9.list;
> public class $REPL11 {
>     public static
>     ? extends String $2;
>     public static Object do_it$() throws Throwable {
>         return $2 =
>         list.iterator().next();
>     }
> }
> ---
>
> Attached is a possible fix - what do you think?
>
> Thanks,
>     Jan
    
    
More information about the kulla-dev
mailing list