I'm trying to create a basic class that stores an array of Objects and returns them. I do not have a way of knowing how many objects I will need to store, so I am using an ArrayList instead of a regular Array. However, code that would work with a regular Array does not appear to function with an ArrayList's get() method. Instead, I get an "Incompatible Types" error when I try to return the results of .get().
Even after creating the smallest possible SSCCE, I still am not quite sure why this doesn't function:
public class EmptyType { int testInt = 1; }
import java.util.*; public class ArrayListTest { private ArrayList list; public ArrayListTest() { list.add(new EmptyType()); } public EmptyType GetFirstIndex() { return list.get(0); } }