Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 520727 - [9] Eclipse rejects anonymous to interface conversion
Summary: [9] Eclipse rejects anonymous to interface conversion
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.6   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: BETA J9   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 497609 (view as bug list)
Depends on:
Blocks:
 
Reported: 2017-08-09 02:59 EDT by Jay Arthanareeswaran CLA
Modified: 2019-11-14 13:06 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jay Arthanareeswaran CLA 2017-08-09 02:59:57 EDT
The following code (with appropriate imports) is rejected by ECJ, but Javac accepts this program:

Object in = new Object() {
	public Object foo() {
		return (Serializable) this;
	}
};

I believe (as per JLS 5.1.6.1, where there's lot of change for Java 9), this is valid.
Comment 1 Stephan Herrmann CLA 2017-08-30 16:36:01 EDT
To figure out the changes in JLS 9 - 5.1.6.1, please see that JLS 8 has similar rules in the body of 5.1.6.

I think the relevant bullets are 

JLS 8:

 From any class type C to any non-parameterized interface type K,
 provided that C is not final and does not implement K.

JLS 9:
 S is a class type, T is an interface type, and S does not name a final class (§8.1.1).

Except for the parameterization issue, both versions basically state the same.

I think what *has* changed is the finalness of anonymous classes.

JLS 8 - 15.9.5

An anonymous class is always implicitly final (§8.1.1.2).

JLS 9 - 15.9.5

An anonymous class is never final (§8.1.1.2).


:)
Comment 2 Eclipse Genie CLA 2017-08-30 16:48:34 EDT
New Gerrit change created: https://git.eclipse.org/r/104035
Comment 4 Stephan Herrmann CLA 2017-08-30 18:30:05 EDT
(In reply to Eclipse Genie from comment #3)
> Gerrit change https://git.eclipse.org/r/104035 was merged to [BETA_JAVA9].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=fce70ab5b1cb13a2f70c1b9062312a09892f1a96
> 

Released for BETA_JAVA9
Comment 5 Stephan Herrmann CLA 2019-11-14 13:06:36 EST
*** Bug 497609 has been marked as a duplicate of this bug. ***