如何在没有包的情况下获取类的名称? [英] How to get the name of a class without the package?

查看:180
本文介绍了如何在没有包的情况下获取类的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,我们有 Type.FullName Type.Name 用于获取类型的名称(类在这种情况)有或没有命名空间(java-world中的包)。

In C# we have Type.FullName and Type.Name for getting the name of a type (class in this case) with or without the namespace (package in java-world).

什么是Java等价于 Type.Name

What is the java equivalent to Type.Name?

显然必须有比使用 Class.getName()更好的方法并剥离它包名称手动。

Clearly there must be a better way than using Class.getName() and strip it of the package name manually.

推荐答案

Class.getSimpleName()


返回源代码中给出的基础类的简单名称。如果基础类是匿名的,则返回一个空字符串。

Returns the simple name of the underlying class as given in the source code. Returns an empty string if the underlying class is anonymous.

数组的简单名称是附加了[]的组件类型的简单名称。特别是组件类型为匿名的数组的简单名称是[]。

The simple name of an array is the simple name of the component type with "[]" appended. In particular the simple name of an array whose component type is anonymous is "[]".

它实际上是从名称中剥离包信息,但这对你来说是隐藏的。

It is actually stripping the package information from the name, but this is hidden from you.

这篇关于如何在没有包的情况下获取类的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆