lambda bugs? referencing instance variable from lambda body
Vicente-Arturo Romero-Zaldivar
vicente.romero at oracle.com
Tue Sep 24 07:01:32 PDT 2013
Hi Zhong Yu,
I created this bug entry for it:
https://bugs.openjdk.java.net/browse/JDK-8024809
Sorry if I didn't send the update to the list,
Thanks,
Vicente
On 24/09/13 14:22, Zhong Yu wrote:
> Hi, has someone looked into these two bugs? Especially the 2nd one
> which is pretty odd.
>
> On Thu, Sep 12, 2013 at 5:59 PM, Zhong Yu <zhong.j.yu at gmail.com> wrote:
>> This compiles . . . . . . . . . . . . . . . . . . . . . . . . .
>>
>> 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
>> }
>> };
>> }
>>
>>
>> Zhong Yu
More information about the lambda-dev
mailing list