Re: local class philosophy
- From: "ricky.clarkson@xxxxxxxxx" <ricky.clarkson@xxxxxxxxx>
- Date: 22 Jan 2006 08:26:11 -0800
> These final but not-known-at-compile-time values are passed to the local
> class's constructor(s), as you can check for yourself using javap.
Interesting, I always thought that was synthetic methods, but it seems
you're right.
<code>
class One
{
void method()
{
final long time=System.currentTimeMillis();
class Local
{
public Local(int test)
{
}
public void method2()
{
System.out.println(time);
}
}
new Local(5).method2();
}
}
</code>
The above gets compiled to look like this:
<code>
class One
{
void method()
{
final long time=System.currentTimeMillis();
new One$1Local(this,5,time).method2();
}
}
class One$1Local
{
public One$1Local(One oneThis,int number,long time)
{
this$0=oneThis;
this.val$time=time;
}
public void method2()
{
System.out.println(val$time);
}
}
So the order is enclosing instance first, then explicit parameters from
the original source, then extra variables as required.
Interesting.
.
- Follow-Ups:
- Re: local class philosophy
- From: Mike Schilling
- Re: local class philosophy
- References:
- local class philosophy
- From: puzzlecracker
- Re: local class philosophy
- From: Thomas Hawtin
- Re: local class philosophy
- From: Torkel Franzen
- Re: local class philosophy
- From: duff
- Re: local class philosophy
- From: Mike Schilling
- local class philosophy
- Prev by Date: Re: Timestamp to a string
- Next by Date: Connection problem with IKVM.net and .net DLL
- Previous by thread: Re: local class philosophy
- Next by thread: Re: local class philosophy
- Index(es):