Page 1 of 1

About Question com.enthuware.ets.scjp.v6.2.84 :

Posted: Sat Dec 14, 2013 6:14 am
by devlam
I did some checks on the behaviour of Arrays.asList() method and found that when you invoke it with a primitive-array it returns a List with primitive arrays (for example List<int[]>) whereas the invocation with an array of a certain object-class it returns a List of that object-class (for example List<String>).

Do you know why they implemented it this way? I was expecting also a List<int> as return value.

Re: About Question com.enthuware.ets.scjp.v6.2.84 :

Posted: Sat Dec 14, 2013 10:06 am
by admin
No, I do not know why it is that way. The API designers would be the best people to answer that.

HTH,
Paul.

Re: About Question com.enthuware.ets.scjp.v6.2.84 :

Posted: Wed May 14, 2014 7:50 am
by vaidaskz
devlam wrote:I did some checks on the behaviour of Arrays.asList() method and found that when you invoke it with a primitive-array it returns a List with primitive arrays (for example List<int[]>) whereas the invocation with an array of a certain object-class it returns a List of that object-class (for example List<String>).

Do you know why they implemented it this way? I was expecting also a List<int> as return value.
I think it's not API designers implementation, but Java's generic method + varargs specification.