Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345239

Summary: [1.7][compiler] Compiler should issue better diagnostics for use of <> with anonymous classes
Product: [Eclipse Project] JDT Reporter: Srikanth Sankaran <srikanth_sankaran>
Component: CoreAssignee: Srikanth Sankaran <srikanth_sankaran>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, deepakazad, Olivier_Thomann
Version: 3.7   
Target Milestone: 3.7.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch + tests none

Description Srikanth Sankaran CLA 2011-05-10 05:33:47 EDT
BETA_JAVA7 head of branch.

public class X<T> {
		X<String> x = new X<>() { };
}

The program above elicits the error message:

"Incorrect number of arguments for type X<T>; it cannot be parameterized with arguments <>"

We could issue a better message that informs the user that his/her attempt to
use <> with anonymous classes is disallowed.
Comment 1 Ayushman Jain CLA 2011-05-10 06:13:56 EDT
This was already part of the initial implementation for the diamond construct in bug 339478 comment 2.
		"2. ERROR in X.java (at line 3)\n" + 
		"	X Test = new X<>(){\n" + 
		"	             ^\n" + 
		"Empty type argument list cannot be used in anonymous class declaration\n" + 
		"----------\n"
Comment 2 Srikanth Sankaran CLA 2011-05-11 01:22:38 EDT
Created attachment 195296 [details]
Proposed patch + tests

Patch under test. Note that prior to this patch, we were rejecting
the illegal programs correctly. Now the message makes it explicit to
the user that diamond cannot be used with anonymous classes.
Comment 3 Srikanth Sankaran CLA 2011-05-11 04:27:51 EDT
Released in BETA_JAVA7 branch.
Comment 4 Deepak Azad CLA 2011-07-19 06:39:20 EDT
Verified with v20110714-1300.