anonymous class questions - why final?

P

puzzlecracker

In this example:

static List<Integer> intArrayAsList(final int[] a)
{
if(a==null)
throw new NullPointerException();

return new AbstractList<Integer>(){
public Integer get(int i){
return a;
}
//and other methods like set and size
};

}

I thought that idea of final in the context of anonymous class that
argument passed to it will not be modified outside of it's scope.
However, here this array a can modified elsewhere, say in the
function that called intArrayAsList, defeating the purpose of final to
begin with.

Please elaborate, why does it have to really be final?

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top