Skip to content

Why does my Netbeans IDE doesn't recognize my generic data type? The error says it cannot find symbol E. #2

Description

@safiullahzuri

import java.util.Arrays;

public class Ex1 {
//implementing methods getSize, peek, push, pop, isEmpty and toString
final int CAPACITY = 100;
int size;
private E[] array = (E[]) new Object[CAPACITY];

public Ex1() {

}
public int getSize(){
    return size;
}
public E peek(){
    if(size == 0)
        return null;
    else
        return array[size-1];
}

public void push(E o){
    array[size++] = o;
    if (size == CAPACITY){
        E[] temp = (E[]) new Object[CAPACITY*2];
        System.arraycopy(array, 0, temp, 0, array.length);
        array = temp;
    }

}

public E pop(){
    if(size==0)
        return null;
    else
        return array[--size];

}

public boolean isEmpty(){
    return size==0;
}

public String toString(){
    return "stack: "+Arrays.toString(array);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions