Bug 424296 - [1.8][quick assist] Conversion from anonymous class to lambda results in ill formed program
Summary: [1.8][quick assist] Conversion from anonymous class to lambda results in ill ...
Status: CLOSED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.3.1   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: BETA J8   Edit
Assignee: Noopur Gupta CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 425412 425410 425411 425413
Blocks:
  Show dependency tree
 
Reported: 2013-12-18 00:47 EST by ANIRBAN CHAKRABORTY CLA
Modified: 2014-03-06 07:56 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ANIRBAN CHAKRABORTY CLA 2013-12-18 00:47:20 EST
interface FIOther<T> {
	<M> FIOther<T> run (M x);
}

public class TestOther {
    FIOther<String> fi1 = new FIOther<String>() {public <M> FIOther<String> run(M x) {return null;}};
    
}


Convert the error free code to lambda expression with quick fix. See the syntax error message :
Illegal lambda expression: Method run of type FIOther<String> is generic 	TestOther.java	/_pasted_code_/src	line 6	Java Problem
Comment 1 Srikanth Sankaran CLA 2013-12-18 01:01:02 EST
Here is another example:

I.java
// --
package p1;
public interface I {
	void foo() throws packagePrivateException;
}

class packagePrivateException extends RuntimeException {
	
}

// X.java

import p1.I;


public class X {
	public static void main(String[] args) {
		I i = new I() {

			@Override
			public void foo() {
			}
			
		};
	}
}

// conversion results in:

"The type packagePrivateException from the descriptor computed for the target context is not visible "
Comment 2 Srikanth Sankaran CLA 2013-12-18 01:09:10 EST
Here is another case where conversion results in loss of information leading
to breakage: 

import java.util.List;


interface I<T> {
	void goo(List<T> i);
}


public class X {
	public static void main(String[] args) {
		I i = new I<String>() {

			@Override
			public void goo(List<String> k) {
				String s = k.get(0);
				
			}
			
		};
		
	}
}
Comment 3 Srikanth Sankaran CLA 2013-12-18 01:12:26 EST
Annotations are lost in this example: 

// --
interface I {
	void goo(String ... strings);
}


public class X {
	public static void main(String[] args) {
		I i = new I() {

			@Override
			public void goo(@T String ... k) {
			
				
			}
			
		};
		
	}
}

@interface T {
	
}
Comment 4 Noopur Gupta CLA 2014-01-10 09:57:29 EST
All the comments here represent different bugs resulting in incorrect conversion to lambda. I will create separate bug reports for each.
Comment 5 Noopur Gupta CLA 2014-03-06 01:34:53 EST
Closing as separate bug reports are created for the issues mentioned here.