N
NeoGeoSNK
"Thomas Hawtin дµÀ£º
"
Thanks Tom Hawtin
And I think AtomicReference is more complex than Inner class
"
Andreas said:An extra note:
This doesn't mean that you couldn't share non-final
references between the outer and inner class! Just
wrap it up into some container-class.
Simple example:
class Outer {
final TextField[] tf = new TextField[1];
class Inner
{
// use and modify tf[0] at will.
}
void init()
{
// use and modify tf[0] at will.
}
}
I'm not sure how useful an example that is. IIRC, it does mean (from
1.5) that you can guarantee that tf[0] is non-null, even with unsafe
publishing. For local classes you can do much the same (but use
AtomicReference):
String foo(String arg) {
final AtomicReference<String> argRef =
new AtomicReference<String>(arg);
new Object() {
void bar() {
argRef.set('<'+argRef.get()+'>');
}
}.bar();
return argRef.get();
}
But please don't.
Tom Hawtin
Thanks Tom Hawtin
And I think AtomicReference is more complex than Inner class