lambda: initial is assignable check; effectively final; acceptable context

This commit is contained in:
anna
2012-07-19 21:18:30 +02:00
parent 714b565acd
commit 812b9a72ea
15 changed files with 303 additions and 24 deletions
@@ -0,0 +1,22 @@
interface I {
int m(int i);
}
public class XXX {
static void foo() {
int l = 0;
int j = 0;
j = 2;
final int L = 0;
I i = (int h) -> { int k = 0; return h + <error descr="Variable used in lambda expression should be effectively final">j</error> + l + L; };
}
void bar() {
int l = 0;
int j = 0;
j = 2;
final int L = 0;
I i = (int h) -> { int k = 0; return h + k + <error descr="Variable used in lambda expression should be effectively final">j</error> + l + L; };
}
}
@@ -0,0 +1,18 @@
interface I {
void m(int x);
}
class Test {
void foo(Object x) {}
void bar() {
foo(<error descr="Operator '!' cannot be applied to '<lambda expression>'">!(int x)-> {}</error>);
foo(<error descr="Lambda expression is not expected here">(int x)-> { } instanceof Object</error> );
}
I bazz() {
foo((I)(int x)-> { });
I o = (I)(int x)-> { };
return (int x) -> {};
}
}
@@ -0,0 +1,9 @@
class XXX {
void foo() {
int k = 0;
int n = 2;
Runnable r = ()->{
<error descr="Variable used in lambda expression should be effectively final">k</error> = n;
};
}
}
@@ -0,0 +1,18 @@
interface I {
int m();
}
class XXX {
int var;
static int ourVar;
static void foo() {
I s = () -> <error descr="Non-static field 'var' cannot be referenced from a static context">var</error> + ourVar;
}
void bar() {
I s = ()->var + ourVar;
}
}
@@ -11,8 +11,9 @@ class Foo {
};
void bazz() {
bar((String s) -> {
System.out.println(s);});
bar<error descr="'bar(I)' in 'Foo' cannot be applied to '(<lambda expression>)'">((String s) -> {
System.out.println(s);})</error>;
bar((int i) -> {System.out.println(i);});
}
void bar(I i){}
}
@@ -0,0 +1,7 @@
class XXX {
Runnable bar() {
<error descr="Incompatible types. Found: '<lambda expression>', required: 'java.lang.Runnable'">return (o)->{
System.out.println();
};</error>
}
}