I have the following static factory method that creates a list view out of an int array:
public static List<Integer> newInstance(final int[] numbers) {
return new AbstractList<Integer>() {
@Override
public Integer get(int index) {
return numbers[index];
}
@Override
public int size() {
return numbers.length;
}
};
}
public static void main(String[] args) {
int[] sequence = {10, 20, 30};
List<Integer> list = ListFactory.newInstance(sequence);
System.out.println("List is "+list);
}
In "Effective Java", Joshua Bloch mentioned this
as an Adapter that allows an int array to be viewed as a list of Integer instances.
However, I remember that Adapter uses composition and the instance of the anonymous list implementation should use the int[] as a member field.
Where exactly is the int[] input parameter stored if it's not a member field of the anonymous list implementation?
I would appreciate if anyone could provide some insights or some links to look for more information.