java - 如何在没有包的情况下获取类的名称?

标签 java

在 C# 中,我们有 Type.FullNameType.Name 用于获取带有或不带有命名空间(java 中的包)的类型(在本例中为类)的名称-世界)。

Type.Name 的 java 等价物是什么?

显然,必须有比使用 Class.getName() 更好的方法并手动将其从包名中删除。

最佳答案

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 "[]".

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

关于java - 如何在没有包的情况下获取类的名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2690333/

相关文章:

java - 关于通过Java Rest Template上传文件

java - 我可以检查字符串是否包含我没有列出的字符吗?

java - 将对象从 SOAP 处理程序发送到 Web 服务

java - 移动到资源文件夹时生成的证书停止工作

java - 如何在不使用 final 关键字的情况下使类不可扩展?

java - 如何在 JAXB 中获取输出(编码(marshal)处理)?

java - toStringBuilder 导致问题

java - 在 Spring Boot 应用程序上的 com.ibm.ws.security.jaspi.ProviderRegistry 上获取 ClassNotFoundException

java - 命令行参数中 * 的问题

java - SonarLint,字符串数组 : Declare this local variable with "var" instead = error