Possible Duplicate:
Java 1.6: Creating an array of List<T>
How can I initialize this array in Java.
Vector<Integer>[] c;
I already try:
Vector<Vector<Integer>[]> a = new Vector<Vector<Integer>[]>();
Vector<Integer>[] c = (Vector<Integer>[])a.toArray();
with the following error:
Exception in thread “main” java.lang.ClassCastException:
[Ljava.lang.Object; cannot be cast to [Ljava.util.Vector; at
app.Program.main(Program.java:38) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
EDIT:
My problems is that I am client from a class that receives an generic array “T[] args” argument, and in my case T is a generic type such Vector, Thanks
I am new in Java.
I don’t think you can create an array of generics.
Check this out. Java 1.6: Creating an array of List<T>
This is because the type information isn’t available at runtime.