??? On the one day, I saw O'relly's book. Suddenly there is a inexplicable impulse, I am also quite a lot.
Technical writer. ??? Technical writers naturally have to have difficult technology, but their own technology is really unable to enter the master of the master.
. Only with yourself exercises, you can do this far more ideal. ??? This time I published an article to try I can do it, if a certain expert can't see me?
Here, he said, you can refer to criticism (it is best to give a little face, don't tell me one article.
not worth). ??? If you write some extremely simple questions, I don't think there are many people, here is here in Java.
Type conversion is good, this topic seems to be very found, but I think you will also gain something. ??? To say type conversion, first, let's talk about Java's data type. Data types in Java are divided into two types
: Basic type, reference type. Basic data types do not have any good words, Byte Char Short Int
LONG FLOAT DOUBLEAN, these types except Boolean, other classes in C language
There is not much difference. Because the topical topics of this article are type conversion, I don't discuss Boolean here.
Usage of values. ??? The following is the reference type. Quote is also called handle in some books, it is very similar to C / C
Pointer, but pay attention to the reference and pointer is not the same concept. The pointer is a variable that stores the address, he
Make C / C programmers flexibly access memory, but this also brings a lot of hidden dangers to the security of the program.
Since the programmer can operate with the arithmetic operation of the pointer, it will destroy other storage orders.
Bit, leading to unexpected results in the program. Quote Inherited the advantages of the pointer, and restrictions
The operation of the address, so he is safe. The reference type includes instances and arrays generated by all classes (no
Tube is an object array or a basic type array implements a Cloneable interface, so he is also a similar thing.
Example), all reference types are inherited from Object. To illustrate a little bit of all variables in Java
It is a reference, whether the reference type is also a basic type. ??? Now you have to formally discuss the type of conversion. People who have used C / C will be very clear about basic types of conversions.
Chu, basic type conversion is divided into type improvement and forced conversion. For example:? INT A = 100;? Long
B = a 100; // This place uses type boost, A 100 increases from int to Long? a = (int) b; // This place uses forced conversion mandatory type conversion in some case to lose Accuracy, such as:? BYTE B;? INT A = 200;?
B = (Byte) a; // Although it is used here to force conversion, since the range of BYTE is -127 to 127 ??? //, forced conversion width will be truncated in Java except for these conversion The type can also be implicitly converted into string, for example:? System.out.print ("conversion" 100); // If there is a string in front of the data connection ????????? // Will implicit conversion into string ??? Reference type conversion implementation is more simple than C , if an object is not in another object
There is any inheritance relationship, then they can't make type conversions. If you want to assign a derived class
Value to the base class object This is called a topped. If you want to assign the base class object to the derived object, you need to be strong.
Types of conversion, this is called discontinuation, and there are some dangers of discontinuation.
A topic, the base class object must be traced from the derived class object. For example: class base {} class child extends base {? Public static void main (string [] args) {?? base base = new child (); // tracered ?? child child = (child) base; // Tracending ?? child child1 = (child) newbase (); // throws ClassCastException exception?}} ??? Finally, talk about the conversion of string and reference types. As mentioned earlier, all objects are from
Object inherited, there is a toString method in Object. This method is all objects
To convert to string, if you want to convert custom classes to String, the safest way is to override Tostr
ING method. As with the basic type, if the object has a String object with connection, the object is implicitly converted.
String, this situation is actually implicitly calling the Tostring method. Here, all the topics about type conversion are finished, this is my first article, I hope everyone is happy.
Huan. ?????? 2004.6.15?