Home > Java > Javagetting Started > body text

Several methods to get class name in java

王林
Release: 2019-11-20 14:47:55
Original
4447 people have browsed it

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template