2013年11月1日星期五

How to get its data type

public class Test {

    public static void main(String[] args) 
    {
System.out.print(12 + 3);//输出的结果的数据类型怎么得到?
    }
}

------ Solution ------------------------------------- -------
determine the type only instance of an unknown type most frameworks are determined to do so .
------ Solution ---------------------------------------- ----
SOUT input the types are String!

------ Solution ------------------------------------ --------
print () have a lot of heavy
------ Solution ---------------------- ----------------------
it is of type String , the reference
public void print (int i)
print integers. According to the platform's default character encoding String.valueOf (int) is converted to a string of bytes generated and fully to write (int) method of the way these bytes are written .
call Integer class toString () method to convert a string
------ Solution ---------------------- String ----------------------
to this thing ? ? ?

System.out.println(new Integer(12+3).getClass());

------ Solution ------------------------------------- -------
12 +3 an int. Just print method using String.valueOf turned into the string to int
see API:


print

public void print (int i)

Prints an integer. The string produced by String.valueOf (int) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write (int) method.

Parameters:
i - The int to be printed
See Also:
Integer.toString (int)


------ For reference only ---------------------------------- -----
this is int ~
------ For reference only ---------------------------------------
not , the result should be String type , you do get is of type Integer .
------ For reference only -------------------------------------- -
OK

没有评论:

发表评论