Java Class.getSimpleName() 和 .getName() 在 Cacao 和 Sun Java 上的行为不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1345317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Class.getSimpleName() and .getName() behaving differently on Cacao versus Sun Java
提问by EdH
Does any one have any idea why this would be happening?
有谁知道为什么会发生这种情况?
This is some modified lines from the Java DBus bindings (2.6)
这是 Java DBus 绑定 (2.6) 中的一些修改行
// don't let people import things which don't have a
// valid D-Bus interface name
System.out.println("type.getName: " + type.getName() + " type.getSimpleName: " + type.getSimpleName() );
if (type.getName().equals(type.getSimpleName())) {
throw new DBusException(_("DBusInterfaces cannot be declared outside a package: " + "type.getName: " + type.getName()
+ " type.getSimpleName: " + type.getSimpleName() ));
}
Now check out the difference in output from Cacao (0.99.4) versus Sun 1.5
现在检查 Cacao (0.99.4) 与 Sun 1.5 的输出差异
@ubuntu:~/tmp/cacao$ java -version
java version "1.5.0_16"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b02)
Java HotSpot(TM) Client VM (build 1.5.0_16-b02, mixed mode, sharing)
@ubuntu:~/tmp/cacao$ cacao -version
java version "1.5.0"
CACAO version 0.99.3+hg
java -Djava.library.path=/usr/lib/classpath:/ho... DBusChat
type.getName: org.freedesktop.DBus type.getSimpleName: DBus
...Exception in thread "main" org.freedesktop.dbus.exceptions.DBusExecutionException: Could not get owner of name 'framez.tests.dbus.DbusChatInterface': no such name
versus...
相对...
cacao -Djava.library.path=/usr/lib/classpath:/ho... DBusChat
type.getName: org.freedesktop.DBus type.getSimpleName: org.freedesktop.DBus
The Exception is unimportant - its being caused by this behavior... Any ideas? Or is this some weird bug with Cacao.
异常并不重要 - 它是由这种行为引起的......有什么想法吗?或者这是可可的一些奇怪的错误。
Does anyone know if .getName() is a VM dependent thing?
有谁知道 .getName() 是否依赖于 VM?
Info:
信息:
GNU Classpath 0.98 on both JVMs DBus bindings 2.6
两个 JVM 上的 GNU 类路径 0.98 DBus 绑定 2.6
采纳答案by Stephen C
This is most likely a bug in the port of GNU Classpath to the Cacao platform. If I recall correctly, most of the methods in the Classpath version of java.lang.Class
delegate to a "vm" class that needs to be implemented for each port of the library.
这很可能是 GNU Classpath 到 Cacao 平台的端口中的一个错误。如果我没记错的话,Classpath 版本中的大多数方法java.lang.Class
委托给需要为库的每个端口实现的“vm”类。
Certainly Class.getSimpleName()
should return the classname without the package qualification.
当然Class.getSimpleName()
应该返回没有包限定的类名。