0

I have this assignment where I'm supposed to use a custom array list. I am quite confused about lists and generics. In the template for our code we're given "private myObj[] objects;", which is from the class myObj.java which only contains attribute of type T called "data". "private myObj[] objects;" looks a lot like an array to me. I thought generics didn't get along with arrays. I tried casting to be able to create enough "space" for 10 elements of type T(generic), but I couldn't do this without compiler errors which only go away when I comment out the casting of an array of type myObj of size 10 as "myObj[]". Help me please. My TA's have not answered my questions.

Mvasq
  • 11
  • 1
  • 1
    `private myObj[] objects = new myObj[10];` ... this no sorcery ... Also: posting code is very helpful to show what you currently have. – Tom Apr 24 '16 at 02:15
  • My bad, I wrote the code from template wrong. It is actually "private myObj [] objects; " since the only attribute of myObj is the generic data of type . I tried : – Mvasq Apr 25 '16 at 02:26
  • My bad, I wrote the code from template wrong. It is actually "private myObj [] objects; " since the only attribute of myObj is the generic data of type . I tried :" objects[index] = new myObj (obj);" to make the "space" for each individual element as it's generated from a for loop. Code compiles and runs but I can't get it to add the "space" and elements into array objects. I keep having a null "Array/list/whatever" of generics myObj. – Mvasq Apr 25 '16 at 02:45

0 Answers0