Type conversion related in Java

Source: Internet
Author: User
float a = 1.5;    Error: 1.5 is the default double type, double cannot be automatically converted to float type, need to cast float B = 1.5f;   Compiled by byte = 1;     Compile through/* Because in Java the value of the default value is int, when assigned to a numeric type variable that has a smaller range than the int type (this unification is called the numeric type k,k can be the Byte/char/short type), it is judged, If this int value exceeds the value type K, then a direct compilation error occurs. Because you assign a value that exceeds the range to a variable of type K, K does not fit, you have no coercion type conversion, of course, error. However, if the value of this int type is still within the value type K range, the JVM will customize an implicit type conversion to convert this int value to type K. */

 

byte m = 1, n = 2, c;c = 1+2;  Compile by C = m+n; Error. Because the value of M+n may exceed the range of byte
c = m+2; Error
c = (byte) (m+n); Compiled by.

  

Reference: http://www.cnblogs.com/lwbqqyumidi/p/3700164.html

Type conversion related in Java

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.