Java 方法变量和包名称之间的命名冲突
我有一些由 Axis 框架从 WSDL 文件生成的类。 在这些类之一中,有一个生成的方法。
public com.initechsystems.www.initech7.initechbo.Organization createOrganization(com.initechsystems.www.initech7.initechbo.Organization org) throws java.rmi.RemoteException {
//(... snip ...)
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
//(... snip ...)
}
方法参数中的变量名称 org 与包 org.apache.axis.client 产生命名冲突,因为编译器无法区分包和变量。 我意识到我可以通过更改方法中的变量名称 org 轻松解决此问题,但我想避免这种情况,因为它会减慢工作流程。 除了修改 WSDL 文件或生成的类之外,还有其他方法可以解决此问题吗?
编译器错误:
D:\projects\java\initechdir\target\generated-sources\axistools\wsdl2java\com\initechsystems\www\initech7\initechws\OrganizationManagement\OrganizationManagementSoapStub.java:[1678,29] cannot find symbol
symbol : variable apache
location: class com.initechsystems.www.initech7.initechbo.Organization
I have some classes generated from WSDL files by the Axis Framework. In one of these classes, there is a generated method
public com.initechsystems.www.initech7.initechbo.Organization createOrganization(com.initechsystems.www.initech7.initechbo.Organization org) throws java.rmi.RemoteException {
//(... snip ...)
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
//(... snip ...)
}
The variable name org in the method parameter creates a naming clash with package org.apache.axis.client, as the compiler cannot differentiate between the package and variable. I realize I can fix this easily by changing the variable name org in the method, but I would like to avoid this, because it slows down the workflow. Is there some way around this other than either modifying the WSDL file or the generated classes?
Compiler error:
D:\projects\java\initechdir\target\generated-sources\axistools\wsdl2java\com\initechsystems\www\initech7\initechws\OrganizationManagement\OrganizationManagementSoapStub.java:[1678,29] cannot find symbol
symbol : variable apache
location: class com.initechsystems.www.initech7.initechbo.Organization
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有没有办法使生成的代码具有 import 语句? 这将使您不必拥有该类的完全限定名称。
因此,如果您可以将: 添加
到文件中,那么您的方法调用将是:
我不确定 Axis 是否有相应的选项。 如果不是,我会说重命名变量(也许重命名为“组织”)将是最好的事情。 我建议避免手动编辑自动生成的文件,因为这会使重新生成它们变得更加困难。
Is there a way to cause that generated code to have import statements? That would prevent you from having to have the fully-qualified name of the class.
So, if you could add:
to the file then your method call would just be:
I'm not sure if Axis has an option for that though. If not I'd say renaming the variable (maybe to "organization") would be the best thing. I would recommend avoiding manual edits of auto-generated files, as that makes regenerating them harder.