Anonymous classes with diamond, subexpression excludes bounds of type variable

Dan Smith daniel.smith at
Tue Jun 9 20:57:47 UTC 2015

> On Jun 2, 2015, at 11:37 AM, Georgiy Rakov <georgiy.rakov at> 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.)

Beyond testability, assertions like this are useful for future-proofing -- if somehow we started inferring the bounds of a type parameter declaration, we wouldn't want that to change the nature of this check.


More information about the compiler-dev mailing list