在 C# 中,我们有 Type.FullName
和 Type.Name
用于获取带有或不带有命名空间(java 中的包)的类型(在本例中为类)的名称-世界)。
Type.Name
的 java 等价物是什么?
显然,必须有比使用 Class.getName()
更好的方法并手动将其从包名中删除。
最佳答案
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 "[]".
它实际上是从名称中剥离包信息,但这对你是隐藏的。
关于java - 如何在没有包的情况下获取类的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2690333/