hi, guys when i read TIJ2 about unsupported operation, it has code like this: String[] s={...}; List a= Arrays.asList(s); and i look the source of jdk, public static List asList(Object[] a) { return new ArrayList(a); } so i look at the ArrayList's constructor, there is no any constructor accept array as prarameter, neither it's ancestor. so how does List produced? can anyone explain for me? thanks michael
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
Hi Michael, I can't answer your question but I'm really curious How did you look at the source for the JDK class?? Thanks ------------------ Jane
Hi michael I think you have been looking for the constructor in the java.util.ArrayList's java file. if you look into java.util.Arrays java file then you can find an inner class "ArrayList" at the end just below the asList() method, which contains the constructor which takes the array as parameter. the inner class which i copied from Arrays is as: private static class ArrayList extends AbstractList implements java.io.Serializable { private Object[] a; ArrayList(Object[] array) { a = array; } public int size() { return a.length; } public Object[] toArray() { return (Object[]) a.clone(); } public Object get(int index) { return a[index]; } public Object set(int index, Object element) { Object oldValue = a[index]; a[index] = element; return oldValue; } }
michael huang
Ranch Hand
Joined: Jul 30, 2000
Posts: 63
posted
0
hi, ali oh, yes, thank you very much, i just look at the file java.util.ArrayList, and not find the inner class arraylist at Arrays. and Just because of this class, so there are many "unsupported operation". BTW Jane, you can extract java source at jkd directory using: jar -xvf src.jar. thank you michael [This message has been edited by michael huang (edited October 20, 2000).]