Description
public class Tmp
{
final Runnable r1 = ()->System.out.println(r1);
}
This does NOT . . . . . . . . . . . . . . . . . . . . . . . . .
public class Tmp
{
final Runnable r1;
final Runnable r2 = ()-> System.out.println(r1); // Error: r1 not
initialized
Tmp()
{
r1 = ()->System.out.println(r1); // Error: r1 not initialized
}
}
This compiles . . . . . . . . . . . . . . . . . . . . . . . . .
public class Tmp
{
final Object lock = new Object();
final Runnable r2 = ()->{
System.out.println(r2);
synchronized (lock){
}
};
}
This does NOT . . . . . . . . . . . . . . . . . . . . . . . . .
public class Tmp
{
final Object lock = new Object();
final Runnable r2 = ()->{
synchronized (lock){
System.out.println(r2); // Error: self-reference in initializer
}
};
}
reported by Zhong Yu in lambda-dev list.
Attachments
Issue Links
- is blocked by
-
JDK-8026854 java.time.temporal.TemporalQueries doesn't compile after javac modification to lambda flow analysis
- Closed
- relates to
-
JDK-8026854 java.time.temporal.TemporalQueries doesn't compile after javac modification to lambda flow analysis
- Closed
-
JDK-8027941 javac fails with "self-reference in initializer" when referencing the static field from lambda
- Resolved
-
JDK-8028059 javac: illegal forward reference since b115
- Resolved
-
JDK-8027677 microbenchmarks failed with self-reference in initializer
- Resolved
-
JDK-8053906 javac is accepting a self-referencing variable initializer inside a lambda expression
- Closed
-
JDK-8025762 8.3.3: Clarify that a field cannot be referenced in its own initializer
- Closed
-
JDK-8077667 'variable may not have been initialized' error for parameter in lambda function
- Closed