Java Programmer Interview Handbook (fourth edition), Java Programming basic concept (1) Type conversion

Source: Internet
Author: User

Issue topic: Type conversion

Page number:37 pages

Title:

Discussion point: the answer is not d, it should be B.

Reason: look at the result of the compiler input below

Knowledge Expansion: boxing and unpacking, = = differs from equals

before also always heard what boxing, unpacking and other (loaded your sister's box, Java concept is more), not too much attention, and later looked at the information, the so-called boxing and unboxing mainly because in Java each of the basic types have a corresponding object type, you such as the underlying type int Corresponds to the integer,long corresponding to the long,double corresponding to double, and so on, why each of the underlying types have a corresponding object type? I think mainly for the convenience of operation, since it is the object type, then of course there will be a variety of methods for use, such as you want to do the basic types of mutual transformation you can first change the underlying type to the corresponding object type, and then through the method provided by this object type for conversion, such as the following example:

What exactly is boxing and unpacking, boxing is that the compiler performs a boxing operation after the underlying type is changed to the corresponding object type, and the reverse is the case. The following blog is a special introduction to Java Boxing and unpacking to share with you

Http://www.cnblogs.com/dolphin0520/p/3780005.html

= = and equals I used almost every day, before this I did not care too much about the differences, and later looked at the information, = = will be based on the occasion to decide what is compared, is the comparison of the object memory address is compared. and equals if you look at the implementation of the Equals, you will find that it first compares the object memory address, if the memory address is equal to return immediately, if the memory address is not equal and then compare the entity, the entity is equal to return, if the entity is not equal finally , the value is compared. My conclusion about this piece is that if you are comparing object types of two base types, it is best to use equals, because the following behavior occurs:

Well, it's written here, I want to go to dinner alone, and then go wash my hair, come back to practice vocal and so on. There is a wrong place to say it, thank you.

Java Programmer Interview Handbook (fourth edition), Java Programming basic concept (1) Type conversion

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.