I’m hoping to get some clarification on a topic which I find very confusing: The relationship between ArrayList / List / ObservableList, which also ties into the differences between Classes and Interfaces. I’ve read multiple texts on the subject, and the more I read, the more confused I become.
Here’s what I do know for certain: ArrayList is a Class, which means you can create as many ArrayList objects as you like. (This is good news for me, because I love working with them.) I’m also learning JavaFX, and there’s a lot of FX objects which take ObservableLists as input. But ObservableLists are Interfaces, not Classes, so forget about creating any ObservableList objects. At first, I assumed that ArrayList was a child class of List, and ObservableList is an Interface to List & any List child Classes. …But reading further, I see that List is actually an Interface, not a Class, and the parent Class of ArrayList is AbstractList. So that didn’t clear up a lot for me.
Another bit that is driving me crazy: In another forum post, a wiser coder gave me this snippet of code to help my ArrayLists accessible via the ObservableList interface:
List<myClass> myList = new ArrayList<myClass>();
While this method of declaring and initializing an ArrayList compiles and works great, I just plumb don’t understand what is going on here. I thought List was an Interface, not a Class, so how can I create a myList object of type List? If I had to guess, I’d suppose that there is an Interface named List and another, separate Class named List, and due to the context here, Java assumes I am referring to the Class.
On a side question, is there a recommended website or text that people could recommend I consult on this topic? I’ve read “Java in a Nutshell,” the Oracle website, different posts on this site, “Java for Dummies,” and “Java in a Nutshell Examples,” but no illumination yet. Any guidance on understanding this topic is wildly appreciated.
Many thanks! -RAO