Learn about the pits that Java encounters

Source: Internet
Author: User

1.

About Java coercion Type conversions
int x = 1;
Byte y = 2;
byte z = 0;
1). z = (byte) (x+y);//forced type conversion succeeded
2). z = (byte) x+y;//forced type conversion error, loss accuracy
The second way to convert X to byte is to give an error.

Resolution: Byte short int is an int after each other, including Byte+byte,short+short, if the three and long types are mutually counted as long types

View the Java code for the variable type/*class Test {public static void main (string[] args) {int i=1; System.out.println (GetType (i)); public static String GetType (Object o) {return O.getclass (). toString (); */

  

Learn about the pits that Java encounters

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.