Java – what did I miss, or varargs break arrays asList?

private void activateRecords(long[] stuff) {
private void activateRecords(long[] stuff) {
    ...
    api.activateRecords(Arrays.asList(specIdsToActivate));
  }

Arrays. Should not be called Does aslist return the long list? Instead, it returns a list < long [] >

public static <T> List<T> asList(T... a)

The method signature is consistent with the result. Varargs throws the entire array into the list It is the same as new arraylist(); list. Add (myArray) Yes, I know it means: arrays asList(T t1,T t2,T t3)

I think what I get is, instead of varargs form, why can't I just use my old aslist method (at least I think this is how it used to work), it will get the content and put them in a separate list? Is there any other clean way to do this?

Solution

That's because long [] and long [] are different types

In the first case, t is long [], and in the second case, t is long

How to solve this problem? Don't use long []?

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>