Java arrays.aslist Issues

Source: Internet
Author: User

1. Questions

 Public Static void aslist () {        System.out.println (arrays.aslist (new string[] {"A", "B" });        System.out.println (Arrays.aslist (new integer[] {1, 2 }));        System.out.println (Arrays.aslist (newint[] {1, 2 }));  
        System.out.println (Arrays.aslist (new object[] {new int[] {1, 2}});
       System.out.println (arrays.aslist (new string[] {"A", "B"}, "C"));

The right way Apache Common Lang
      System.out.println (Arrays.aslist (Arrayutils.toobject (new int[] {1, 2}));

}

[A, b]
[1, 2]
[[[Email protected]]

[[[Email protected]]

[[Ljava.lang.string;@2077d4de, C]

[1, 2]

Because the Java language specification calls for calling a method that is declared as Foo (t ... t), such as foo (new T[]{bar,baz}) is equivalent to a call such as Foo (Bar,baz). In the Arrays.aslist method, T is the parameter type,

So it must be an object type, but int is not, and int[] is. Arrays.aslist, as a negative case, tells us why we should be very careful when using the variable parameter design API for Java.

Reference:

Http://www.importnew.com/14996.html

Java arrays.aslist Issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.