So I'm working in Java and I want to declare a generic List.
So what I'm doing so far is List<T> list = new ArrayList<T>();
But now I want to add in an element. How do I do that? What does a generic element look like?
I've tried doing something like List.add("x") to see if I can add a string but that doesn't work.
(The reason I'm not declaring a List<String>
is because I have to pass this List into another function that only takes List<T>
as an argument.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…