mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-26 08:45:34 +07:00
lambda: initial is assignable check; effectively final; acceptable context
This commit is contained in:
+22
@@ -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; };
|
||||
}
|
||||
}
|
||||
+18
@@ -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) -> {};
|
||||
}
|
||||
}
|
||||
+9
@@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
+18
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user