0

I have created a parent class Object with 3 parameters, a child class ObjectA with 4 parameters and a child class ObjectB with 8 parameters. These parameters have different data types. I need to read a csv file A (with 4 columns) and a csv file B (with 8 columns) into one ArrayList< Object>. Is this possible?

joe.moss
  • 1
  • 3
  • Maybe this would help: https://stackoverflow.com/a/40074903/10743176 ? Just that you need one ArrayList and two loops, one for each of your csv-file/Subclass. – Alex Funk Aug 02 '20 at 09:15
  • When you say "parent class Object with 3 parameters", do you mean the constructor has 3 parameters? – Scratte Aug 02 '20 at 10:40
  • @Scratte yes the Object constructor has 3 parameters, ObjectA 4 and ObjectB 8 (noting user1855085 's comment below that it can't be called Object - so I will change it to something else) – joe.moss Aug 02 '20 at 11:19

1 Answers1

0

Yes, it's possible, except that the parent class cannot be called 'Object'.

    ArrayList<ObjectParent> list = new ArrayList<ObjectParent>();
    list.add(new ObjectA(aPath));
    list.add(new ObjectB(bPath));
Andrew Arthur
  • 1,563
  • 2
  • 11
  • 17
  • I tried but it wasn't happy because the number of parameters for ObjectParent, ObjectA and ObjectB are different :( – joe.moss Aug 02 '20 at 11:50