mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 10:51:25 +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;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -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){}
|
||||
}
|
||||
+7
@@ -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>
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user