Dc Redwing
Dc Redwing

Reputation: 1791

How to create array of concrete parameterized type without using @SuppressWarnings("unchecked")

I just start to learn Java and I am getting "@SuppressWarnings("unchecked")"

I am sure that one of my static variable is making trouble

static ArrayList<Integer>[] docNumber = (ArrayList<Integer>[]) new ArrayList[20];

eclipse said "Type safety: Unchecked cast from ArrayList[] to ArrayList[]" but i am not really sure how to avoid this problem

can you tell me how to fix this problem?

thanks

Upvotes: 1

Views: 258

Answers (3)

dan
dan

Reputation: 13272

In order to avoid the @SuppressWarnings(“unchecked”) you should give the compiler the information needed to perform all type checks that would be necessary to ensure type safety, see unchecked FAQ.

In your case, I assume that you are trying to maintain a list of document integers, for this you will need:

List<Integer> docNumber=new ArrayList<Integer>();

If you would like to keep a list of lists then you can do:

List<List<Integer>> docNumber=new ArrayList<List<Integer>>();

Upvotes: 1

Yogendra Singh
Yogendra Singh

Reputation: 34367

Are you trying to achieve this (List of Array Of Integer)?

   static ArrayList<Integer[]> docNumber = new ArrayList<Integer[]>();

Upvotes: 0

Dmitri
Dmitri

Reputation: 9157

Can't be avoided with arrays.

Use a List<List<Integer>> instead.

Upvotes: 2

Related Questions