I would like to write a method which helps me to store some stuff in the generics class variable. I don't understand a concept a little bit :(
I would like to write a method which replace this simple solution:
a.myObject[0]=tracks;
and will works with others elements when I give as a parament an array index
I would like to figure out something like this method (but as a set a value). Does anybody have a clue how to do it?
E get(int i) {
return (E) myObject[i];
}
My source code:
import java.util.Arrays;
import java.util.List;
public class GenericArray<E>{
private Object[] myObject;
public GenericArray(int s) {
myObject = new Object[s];
}
E get(int i) {
return (E) myObject[i];
}
public static <Track> void main(String[] args) {
GenericArray a = new GenericArray(100);
List<String> tracks = Arrays.asList("One", "Two", "Three");
PlayList play = new PlayList(tracks);
a.myObject[0]=tracks;
System.out.println(a.get(0));
}
}