How does the JLS specify that wildcards cannot be formally used within methods?

前端 未结 3 2004
Happy的楠姐
Happy的楠姐 2020-12-11 08:40

I\'ve always been wondering about some weird aspect of Java generics and the use of wildcards. Let\'s say, I have the following API:

public interface X

        
3条回答
  •  旧时难觅i
    2020-12-11 09:00

    I've just seen this peculiar implementation of Collections.swap():

    public static void swap(List list, int i, int j) {
        final List l = list;
        l.set(i, l.set(j, l.get(i)));
    }
    

    The JDK guys resort to a raw type, in order to handle this, locally. To me, this is a strong statement indicating that this probably should be supported by the compiler, but for some reason (e.g. lack of time to formally specify this) just wasn't done

提交回复
热议问题