I want to add methods to return the list or particular element and I want it to work with any generic class. Why isnt Java allowing this?
class ArrayListBuilder<E>{
private ArrayList<E> a_list=new ArrayList<>();
}
I want to add methods to return the list or particular element and I want it to work with any generic class. Why isnt Java allowing this?
class ArrayListBuilder<E>{
private ArrayList<E> a_list=new ArrayList<>();
}
I tried to compile your code and got these errors
ArrayListBuilder.java:2: error: cannot find symbol
private ArrayList<E> a_list=new ArrayList<>();
^
symbol: class ArrayList
location: class ArrayListBuilder<E>
where E is a type-variable:
E extends Object declared in class ArrayListBuilder
ArrayListBuilder.java:2: error: cannot find symbol
private ArrayList<E> a_list=new ArrayList<>();
^
symbol: class ArrayList
location: class ArrayListBuilder<E>
where E is a type-variable:
E extends Object declared in class ArrayListBuilder
2 errors
As you can see there actually are two errors, the first one meaning that you need to import java.util.ArrayList. Once you do that, your code compiles fine. So put in the first line of your code
import java.util.ArrayList;
TL;DR: the solution to your problem is reading all of the error messages. Not just the last one.