United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7046778 Project Coin: problem with diamond and member inner classes
JDK-7046778 : Project Coin: problem with diamond and member inner classes

Details
Type:
Bug
Submit Date:
2011-05-20
Status:
Closed
Updated Date:
2012-02-24
Project Name:
JDK
Resolved Date:
2012-02-24
Component:
tools
OS:
generic
Sub-Component:
javac
CPU:
unknown
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:

Sub Tasks

Description
This program does not compile:


class X<T> {
    class Y<Z> {
         Y(T a, Z b) { }
    }

    public static void main(String[] args) {
        X<String>.Y<String> x1 = new X<String>().new Y<String>("",""); //ok
        X<String>.Y<String> x2 = new X<String>().new Y<>("",""); //fails
    }
}

                                    

Comments
EVALUATION

It appears that javac doesn't handle type-variable substitution consistently when diamond oerator is used in conjunction with member classes. The problem lies in the fact that javac attributed a diamond AST node as follows:

new X<String>.new Y<>

has type:

X<String>.Y

[where Y is 'raw']

This leads to problem when the synthetic constructor is accessed as a member of X<String>.Y, as javac tries to replace formal type-vaiables (T,Z) with a set of actual arguments which is smaller (String). This lead to a bad substitution and to a spurious compiler error.

In order to guarantee better interoperability with type-variable substitution, the diamond AST node should be attributed as:

X<String>.Y<Z>
                                     
2011-05-20
SUGGESTED FIX

A webrev of this fix is available at the following URL:
http://hg.openjdk.java.net/jdk8/tl/langtools/rev/d5f33267a06d
                                     
2011-07-28



Hardware and Software, Engineered to Work Together