Local variable is only accessible from inside the scope it is local to - usually, a function. It doesn't matter if it is final or not or if it is an inner class.
Perhaps, you meant an anonymous class?
Something like:
class Pair
{
int l,r;
...
public Comparator getComparator (boolean left)
{
return new Comparator ()
{
public int compareTo (Object o)
{
return left ? l - ((Pair) o).l : r - ((Pair) o).r;
}
}
}
}
Here the object returned by getComparator () is an anonymous class, extending a Comparator. This snippet won't compile becaus it references 'left', that is not final - such constructs are simply not allowed. You have to declare it final to compile.
So, if this is what you meant, then the answer to your question - "what happens" - is "nothing happens", it simply won' t compile
2007-01-21 13:58:44
·
answer #1
·
answered by n0body 4
·
0⤊
0⤋