Home>Article>Java> Several methods to get class name in java

Several methods to get class name in java

王林
王林 Original
2019-11-20 14:47:55 4386browse

Several methods to get class name in java

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.

Several methods to get class name in java

Result:

Several methods to get class name in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to output data in java Next article:How to output data in java