0

I have been out of touch with Java for a while and trying to create an array of generics and a bit confused.

For regular types I can do things like this:

 String s[] = new String[10];

However if I have my own data type say a bag of integers and I want to define an array of Bag why can't I do this:

 Bag<Integer> b[] = new Bag<Integer>[10];

Neither can I do this:

 Bag<Integer> b[] = (Bag<Integer>) new Object[10];

The above doesnt work, how do I fix it?

EDIT: I saw the "duplicate" answer before I posted but I am unable to figure out how to use information in that answer to solve my problem. I have boiled down my issue to the simplest form and it doesnt appear to be the same.

user2399453
  • 2,378
  • 2
  • 22
  • 49

0 Answers0