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?

1
  • same like this 'List<Integer> li[] = new ArrayList[2];' here implicit type casting, in your case it just explicitly type casting Commented Oct 19, 2018 at 16:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.