unboxing or toString() is used in sysout in java -


We know that when we use it internally in the sysout (System.out.Println) statement, this string The method is called. And prints directly with the primitive. But when we use objects in a wrapper class type, it is considered to be used:

  integer I = new integer (10) System.out.Println (i);  

Is it responsible for printing (unreading) or unboxing?

A quick test and debug run shows that print (object) Applies, print (int) no.

A good way to check is:

  integer value = null; System.out.print (val);  

If UN-Boxing was used, then it would throw a NullPointerException. It does not happen, however, this prints the string null , which is the output of String.valueOf (object) when a blank elapses.

Another factor to keep in mind is that PrintStream exists before Java 5. It could be ensured that when AutoBoxing was introduced in Java 5 That the PrintStream will not change his behavior suddenly, so to call any existing code to print, , suddenly its behavior is print (int) Instead of calling, due to the convenience of a new language, there should not be a call. Backwards compatibility should always be maintained.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -