Anonymous classes with diamond, subexpression excludes bounds of type variable
Dan Smith
daniel.smith at oracle.com
Tue Jun 9 21:31:31 UTC 2015
> On Jun 9, 2015, at 2:57 PM, Dan Smith <daniel.smith at oracle.com> wrote:
>
>> On Jun 2, 2015, at 11:37 AM, Georgiy Rakov <georgiy.rakov at oracle.com> wrote:
>>
>> Hello,
>>
>> new assertion for the new "anonymous classes with diamond" feature specified in JDK-8073593 comment states:
>> The term "subexpression" includes type arguments of parameterized types (4.5), bounds of wildcards (4.5.1), and element types of array types (10.1). It excludes bounds of type variables.***
>> The part of assertion I'm interested in is emphasized above. Could you please tell if you consider this part of assertion as testable and if you do could you please provide the example of the code verifying this assertion.
>
> So, the test case we're after: inference produces a type variable as a type argument, and that type variable is valid, but it has a bound that is not valid.
>
> Something like:
>
> <T extends _____> void test() {
> List<T> list = new ArrayList<>(){};
> }
>
> We know that the bounded variable, T, "was declared as a type parameter", because otherwise the variable itself would be invalid. That limits the set of possible bounds to those that can be declared.
>
> So, can the _____ be "A type variable (4.4) that was not declared as a type parameter (such as a type variable produced by capture conversion (5.1.10))"? Nope.
>
> Can the _____ be "An intersection type (4.9)"? Maybe -- depends how you interpret the bound. (Is "T extends Foo & Bar" a variable with two bounds, or a variable with a single intersection type bound?) Wouldn't hurt to test this case. (Expected behavior is no error.)
I forgot this bullet, which was added later in the discussion:
Can the _____ be "A class or interface type, where the class or interface declaration is not accessible from the class or interface in which the expression appears"? We know that the anonymous class must appear within the scope of the variable declaration, and that the class is accessible at the point of the variable declaration. So I think this case cannot occur: if a type is accessible at the point of a generic class or method declaration, it must also be accessible within the entire body of that class or variable declaration, including any contained anonymous class expressions.
—Dan
More information about the compiler-dev
mailing list