-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

1
  • tldr: LinkedHashMap<X,Y>[] is not possible Commented Oct 3, 2017 at 9:00

1 Answer 1

1

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

function_labels = ( LinkedHashMap<Integer, String>[]) new LinkedHashMap<?,?>[2];
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Benjamin. Wouldn't have guessed that answer in decades!!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.