There are three main ways to obtain class names in Java.
getName()
Returns the class name representation of the class in the virtual machine.
getCanonicalName()
Returns a more understandable representation of the class name.
getSimpleName()
Returns the short name of the class.
Let’s take a look at their main differences through an example.
Result:
Conclusion:
1. From the above results, we can see that getName( ) and getCanonicalName() have no difference when getting ordinary class names, but there are differences when getting inner classes and array classes.
2. There is no difference between getSimpleName() when getting the names of ordinary classes and internal classes, but there is a difference when getting the array class.
Recommended tutorial: Getting started with java development
The above is the detailed content of Several methods to get class name in java. For more information, please follow other related articles on the PHP Chinese website!