0

I am getting a compile error. "warning: [unchecked] unchecked conversion"

ArrayList[] regionTroops = new ArrayList[2];
required: ArrayList[] found: ArrayList[]

public class ContClass {
String name;
ArrayList<Integer>[] regionOwned = new ArrayList[2];
}

The code works, but I would like to eliminate the warning. I set the value as follows.

ContData[n].regionOwned[0].add(rn);
GaryK4
  • 245
  • 1
  • 2
  • 9

1 Answers1

0

If you use a good IDE, it would help to add the annotation needed to suppress the warning.

Since you don't seem to be using such an IDE, here's the annotation you need:

@SuppressWarnings("unchecked")
ArrayList<Integer>[] regionOwned = new ArrayList[2];

The warning is there to tell you that you're not going to get an array of ArrayList<Integer>, so the code will not be as type-safe as it's supposed to be.

See also: How to create a generic array in Java?

Andreas
  • 138,167
  • 8
  • 112
  • 195