-2

I've declared a variable as:

LinkedHashMap<Integer, String>[] function_labels;

but when I try and instantiate it with:

function_labels = new LinkedHashMap<Integer, String>[2];

I get a 'generic array creation' error.

I've searched on here, and although there are many posts about this error message, no-one seems to have offered a solution which actually works, so I'm trying again...

I don't mind what type of collection function_labels is, as long as it works and I can access indexed members of it later. A simple array seems the 'lightest' solution, but there may be others which will work.

Thanks

radders
  • 875
  • 8
  • 24

1 Answers1

1

you have to cast type to declare like this Generic Array Creation

function_labels = ( LinkedHashMap<Integer, String>[]) new LinkedHashMap<?,?>[2];
Benjamin
  • 2,169
  • 1
  • 12
  • 20