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
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