Java 方法变量和包名称之间的命名冲突

发布于 2024-07-15 09:02:58 字数 898 浏览 8 评论 0原文

我有一些由 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈场末日恋爱 2024-07-22 09:02:58

有没有办法使生成的代码具有 import 语句? 这将使您不必拥有该类的完全限定名称。

因此,如果您可以将: 添加

import org.apache.axis.client.Call;

到文件中,那么您的方法调用将是:

_call.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);

我不确定 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:

import org.apache.axis.client.Call;

to the file then your method call would just be:

_call.setProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文