Different types of conversions and enhancements in Java

xiaoxiao2021-03-06  66

04-12-2 21:35

The problem that occurs when converted to INT is that the range of ME is uneven, but the negative value of the range of the BYTE, but when converted to int, there is a negative value, which has a lot of trouble. At that time, the mood was very mood, and I hurriedly talked a few ways to continue the project, but the real reasons have not been able to solve it, become a heart disease. Later, I thought I have read the language normcript manual of Java, and I mentioned these content, so I will take a look at it, I hope to do these things.

In the Java language, the conversion can be divided into seven categories:

First, Identity Conversions.

It doesn't use it, but it is the cornerstone of the entire conversion system. Tip: The Boolean basic type can only perform similar conversion.

Second, Widening Primitive Conversions (Basic Type Widening Conversion).

In the case of the number of bytes, the single byte is a so-called broadcase, such as 1 to 2, 2 to 4, etc.. INT to other integer types of conversion, Float to Double is no distortion, exactly the same. However, although the conversion of integers to floating point is widened, because the floating point number is expressed in the way of effective numbers, accuracy loss may occur (FLOAT type cannot support 9 effective numbers), such as I = 1234567890; FLOAT PP = I - (float) I; PP does not equal to zero. Method with symbol INT conversion to other integer types is the two-bit complement mode of its number with symbol extensions [this ME encounters the key BYTE- "INT] of the problem, the CHAR type is converted to the int type method to perform 0 expansion . Tip: No matter whether the accuracy is lost, the expansion conversion cannot cause runtime errors.

Third, Narrowing Primitive Conversions (Basic Types Narcoid Conversion).

The integer of the symbol is narrowed to other integer types only the low value, except that the symbol change may occur in addition to precision loss. CHAR is narrowed to other integer types, although char is no symbol number.

Fourth, Widentening Reference Conversions (Reference Type Change Conversion).

Subclasss to the parent class. Tip: The number is also a reference type.

V. Narrowing Reference Conversions (Reference Types Repairing).

The parent class into the subclass.

Sixth, String Conversions.

7. Value Set Conversions.

Specifies the number of floats.

In five cases, it is Assignment Conversion.

A useful method is found, and the value can be used to use long.toString (L, 16); Integer, Tostring (i, 8); can be used any.

转载请注明原文地址:https://www.9cbs.com/read-84934.html

New Post(0)