I can do this:
public class className {
public static void main(String[] args){
    Storage<Book> bookstorage = new Storage<Book>(100);
}
public class Storage<E> implements GenStorage<E>{
private int size;
private E [] array = (E[]) new Object[100];
public Hylle(int size){
    this.size = size;
    for (int i = 0; i<size; i++){
        array[i] = null;
    }
}
while this gives me an ArrayIndexOutOfBoundsException:
public class Storage<E> implements GenStorage<E>{
private int size;
private E [] array = (E[]) new Object[size];
public Hylle(int size){
    this.size = size;
    for (int i = 0; i<size; i++){
        array[i] = null;
    }
}
The program runs while the size of the array is equal too or greater than the set size of the object. Why does this happen, and how can I fix it? Thank you in advance.
Edit: Fixed it, I just had to do this:
public class Storage<E> implements GenStorage<E>{
private int size;
private E [] array;
public Hylle(int size){
    this.size = size;
    array = (E[]) new Object[size];
    for (int i = 0; i<size; i++){
        array[i] = null;
    }
}
 
     
     
    