After mastering the package knowledge, you can create your own tool library to reduce or eliminate repeated program code. For example, create an alias for system. Out. println () to reduce the input burden.
Package edu. foresthe. mytools;
Public class P {
Public static void RINT (string s ){
System. Out. Print (s );
}
Public static void rintln (string s ){
System. Out. println (s );
}
}
It can be guessed that the file is located at a classpath, followed by the Directory of edu/foresthe/mytools. After compilation, you can use the Import Statement to use the p. Class file on your system.
Import edu. foresthe. mytools .*;
Public class mytoolstest {
Public static void main (string [] ARGs ){
P. rintln ("available from now on !");
P. rintln ("" + 100); // force it to be a string
P. rintln ("" + 100l );
P. RINT ("" + 3.1415926 );
}
}
Additional topic: As long as all objects are placed in a string expression, they can be easily forcibly converted to a string expression. In the above example, the expression starting with an empty string is this method. However, if you call system. Out. println (100), it does not need to convert 100 to a string to work (rintln ). You can use the P class to achieve the same purpose through some additional overloading.
Congratulations, from now on, as long as you have implemented a new useful tool, you can add it to your own tool library.