1

I have some troubles understanding the statement of 'object array' in Java.

As far as I know, the declaration of object arrays is no different than that of the primitive datatypes;

So it goes like

Car[ ] arr = new Car[some integer];

But while reading some codes, I came to see the statements below.

List<Integer>[ ] B = (LList<Integer> [ ] ) new LList[MaxKey];

(Here List and LList mean data structure 'list' and 'linked list' respectively. And lets assume there is no problem in inheritance.)

My question here is that rhs seems quite new to me. According to the Car array example, shouldn't it be like

new LList<Integer>[MaxKey] 

?

Is it the use of generics that made some variation?

JB Nizet
  • 633,450
  • 80
  • 1,108
  • 1,174
Rhee
  • 785
  • 1
  • 5
  • 17
  • same like this 'List li[] = new ArrayList[2];' here implicit type casting, in your case it just explicitly type casting – Pandey Amit Oct 19 '18 at 16:11

0 Answers0