I am trying do something like this:-
public static ArrayList<myObject>[] a = new ArrayList<myObject>[2];
myObject is a class. I am getting this error:- Generic array creation (arrow is pointing to new.)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can’t have arrays of generic classes. Java simply doesn’t support it.
You should consider using a collection instead of an array. For instance,
Another “workaround” is to create an auxilliary class like this
and then create an array of
MyObjectArrayList.Here is a good article on why this is not allowed in the language. The article gives the following example of what could happen if it was allowed: