Fill a hole
java learning - string output ljava lang.String;@ 15db9742 problem_ Rookie's world - CSDN blog)
It is said here to dig a pit, but it has not been filled in. Once in a while, I found the following comment that you dug a pit but filled it.
I'm really sorry. It's not a good habit to dig a hole without filling it,
Although these articles were written 7 years ago on November 15, 2014 at 01:13:18,
In short, with system out. Println () is related to and independent of it. Specifically, it is related to the toString method of Object
Now the IDEA has automatically explained for you. At this time, String [], implicitly calls the method of String array toString()
In fact, the String [] at this time is treated as an Object in Java. If you don't believe it, you can click println,
You can see that the following method is skipped, that is, Java. Net is called io. Printstream#println (object x) method
/** * Prints an Object and then terminate the line. This method calls * at first String.valueOf(x) to get the printed object's string value, * then behaves as * though it invokes <code>{@link #print(String)}</code> and then * <code>{@link #println()}</code>. * * @param x The <code>Object</code> to be printed. */ public void println(Object x) { String s = String.valueOf(x); synchronized (this) { print(s); newLine(); } }
If you continue tracing, string. Will be called Valueof (x) x here must also be an Object object,
/** * Returns the string representation of the {@code Object} argument. * * @param obj an {@code Object}. * @return if the argument is {@code null}, then a string equal to * {@code "null"}; otherwise, the value of * {@code obj.toString()} is returned. * @see java.lang.Object#toString() */ public static String valueOf(Object obj) { return (obj == null) ? "null" : obj.toString(); }
As you can see, this is a direct call to the toString() method of Object.
/** * Returns a string representation of the object. In general, the * {@code toString} method returns a string that * "textually represents" this object. The result should * be a concise but informative representation that is easy for a * person to read. * It is recommended that all subclasses override this method. * <p> * The {@code toString} method for class {@code Object} * returns a string consisting of the name of the class of which the * object is an instance, the at-sign character `{@code @}', and * the unsigned hexadecimal representation of the hash code of the * object. In other words, this method returns a string equal to the * value of: * <blockquote> * <pre> * getClass().getName() + '@' + Integer.toHexString(hashCode()) * </pre></blockquote> * * @return a string representation of the object. */ public String toString() { return getClass().getName() + "@" + Integer.toHexString(hashCode()); }
getClass() here is to get the type and type of the object, which can also be called the prototype of the object, that is, the class corresponding to the object
In the Java world, there are two concepts, one is called class and the other is called object,
Many mappings mentioned by others may make your concept more vague, but I think there is something that may make you better understand,
That's the seal and seal,
Printing is something that needs to be engraved in advance. This is consistent with the class. You define a bunch of method attributes in advance. When you really use them, you generally won't change the attributes and methods in the class (of course, you can change them if you really want to change them, and you can learn reflection later). When you let you engrave them, you probably won't change them.
A seal is a mark of different colors made by dipping a seal in different inks. It is also called a seal or a seal,
This is consistent with the process of obtaining objects through classes in Java.
String a = new String();
String b = new String()
Here, String is the class, a and B are the objects of String. The class is unique in Java, and there can be multiple objects,
OK, then we understand java What is lang. string? This is the object referred to by "copyboy", "is" and "student"
But why is there [L this,
/** * Returns the runtime class of this {@code Object}. The returned * {@code Class} object is the object that is locked by {@code * static synchronized} methods of the represented class. * * <p><b>The actual result type is {@code Class<? extends |X|>} * where {@code |X|} is the erasure of the static type of the * expression on which {@code getClass} is called.</b> For * example, no cast is required in this code fragment:</p> * * <p> * {@code Number n = 0; }<br> * {@code Class<? extends Number> c = n.getClass(); } * </p> * * @return The {@code Class} object that represents the runtime * class of this object. * @jls 15.8.2 Class Literals */ public final native Class<?> getClass();
When you view the source code, you can only see a method definition, but you can't see what it is. This is actually a JVM native method, so it's not the code written in java. You need to view the JVM code,
You can dig a hole. When someone leaves a message to see the content of this piece, you can add it.
Directly to the conclusion,
Java type | Symbol |
---|---|
Boolean | Z |
Byte | B |
Char | C |
Short | S |
Int | I |
Long | J |
Float | F |
Double | D |
Void | V |
Objects object | Start with "L" and start with ";" At the end, the package and class names separated by "/" are in the middle. For example: Ljava/lang/String; If it is a nested class, use $to represent nesting. For example "(Ljava/lang/String; landroi / OS / FileUtils $filestatus;) Z" |
In addition, the abbreviation of array type can be expressed by "[" plus the abbreviation of corresponding type as shown in table A,
For example: [I means int [];
[L/java/lang/objects, representing Objects [],
Then the [L/java/lang/String] we obtained above obviously represents an array of string type, which is logical.
In addition, the identification of reference types (except arrays of basic types) has a ";" at the end
For example:
"() V" means void Func();
"(II)V" means void Func(int, int);
“(Ljava/lang/String;Ljava/lang/String;)I”. Indicates int Func(String,String)
Therefore, this pit will be filled here for the time being. If the school is abandoned, you can continue to leave a message for discussion.