이것은 실행하려고하는 addToEnd 메소드가있는 MyArrayList의 첫 번째 클래스입니다.addToEnd 메소드를 어떻게 실행합니까?
public class MyArrayList <E extends Comparable<E>>implements List<E> {
private E[] data;
private int size = 0;
private void reallocate(){
size = 2 * size;
data = Arrays.copyOf(data, size);
}
public boolean addToEnd(E e) {
if (size == data.length){
reallocate();
}
data[size++] = e;
System.out.println();
return true;
}
내 두 번째 클래스, ArraySorterTester, 나는 내 addToEnd 메소드를 호출하려고하지만 어떤 이유로 작동하지 않습니다 나는 오류가 계속 곳입니다.
public class ArraySorterTester {
public static void main(String [] args){
Integer[] test = new Integer[] {1, 2, 4, 6, 8 };
MyArrayList<Integer> inserter = new MyArrayList<Integer>();
boolean sorted = true;
inserter.addToEnd(10);
for (int k = 0; k < test.length; k++) {
System.out.print(test[k] + " ");
}
}
어떤 오류가 발생합니까? – Lesleh
at MyArrayList.addToEnd (MyArrayList.java:42) ArraySorterTester.main (ArraySorterTester.java:25) 그것은 어떤 행이 잘못되었는지 알려주지 만 해결 방법이 없습니다 ... 할 일이있을 것 같아요. 내가 어떻게 부르는 지. 또는 아마도이 라인을 잘못 작성했습니다. MyArrayList inserter = new MyArrayList (); 그러나 나는 정말로 내가 뭘 잘못하고 있는지 모르겠다. –