So I'm simulating a File system for my Operating Systems class. I'm kinda lazy and didn't want to do it in C, so I did it in Java :(. I also didn't make any new data structures, I just made a File and Directory class, where the Directory class has an attribute called contents, which is an ArrayList<Object> that contains File and Directory objects.
In the client program, however when I call getContents() on a particular directory, I get an ArrayList<Object>, and when I take the objects out, I can't perform any of the File or Directory methods, even if I cast them to that particular data type.
Why can't I do this? Is there any way to do it where you can have one ArrayList holding both objects that you can manipulate? That seems alot easier and more elegant than the workaround I decided to do, where a directory has two ArrayLists. One is an ArrayList<File> files, and the other is ArrayList<Directory> directories.
Thanks