Automatic unboxing of Java wrapper classes

Source: Internet
Author: User
Tags wrapper

Topic:

integer i =  42 long l = 42l; double d =  42.0

The following is true

A. (i = = L)

B. (i = = d)

C. (L = = d)

D.i.equals (d)

E.d.equals (L)

F.i.equals (L)

G.l.equals (42L)

Answer: G

parsing:Comparisons of the same type, such as Integer and Int,long, are automatically removed when compared with long = =, and are compared between different types, and if one is a non-wrapper class, the box is automatically removed. If both parties are wrapper classes, they will not be disassembled and cannot be compared, and the compilation will error, so ABC is wrong. DEF calls the Equals method, because this method first compares types, and I, D, l are different types, so return false. Option G, which is automatically boxed, boxing 42L into a Long type, so when the Equals method is called, the type is the same and the value is the same, so it returns true.

Automatic unboxing of Java wrapper classes

Related Article

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.