Java GetClass () returns a class. How can we get a string?
•
Java
When I use system out. Println (obj. Getclass()) it doesn't give me any errors Return a class type from getClass () as I understand it
Solution
All objects in Java inherit from the class object If you look at the document, you will see that object specifies a toString method that converts the object to string Since all non - primitive types (including classes) are objects, anything can be converted to a string using its toString method
Class can override this method to provide its own way to convert to a string For example, the string class overrides object ToString to return itself Class overrides the name of the class it returns This specifies how objects are exported
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码