On Jan 29, 3:55 pm, Jason Proctor <[email protected]>
wrote:
> yeah i'm clear on why final's more conventional uses, but does it
> really change the scope of a variable so that it sticks around for an
> anonymous class to use it at an unspecified later time -- onClick()
> etc? doesn't seem right somehow.
Let me clarify my earlier statement with an example. Consider this:
----- Blah.java -----
public class Blah {
public Hoser test() {
int x = 27;
return new Hoser() {
private int i = x;
};
}
}
class Hoser {}
-----
If you compile this with javac, it will complain:
Blah.java:6: local variable x is accessed from within inner class;
needs to be declared final
private int i = x;
^
1 error
If you change the declaration to "final int x = 27", it succeeds.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en