返回类型与Object.getClass()不兼容 [英] Return Type incompatible with Object.getClass()

查看:62
本文介绍了返回类型与Object.getClass()不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码是在eclipse上导入Web服务文件时生成的.但是,我在编译时看到此错误(返回类型与 Object.getClass()不兼容).

the code is generated upon importing a webservice file on eclipse. However, I saw this error upon compiling (return type incompatible with Object.getClass()).

有什么办法解决这个问题吗?

Any ideas to fix this?

public java.lang.String getClass(){
    return localClass;
}

添加:

   if (localClass != null){
                                            elementList.add(org.apache.axis2.databinding.utils.ConverterUtil.convertToString(localClass));
                                        } else {
                                           throw new org.apache.axis2.databinding.ADBException("Class cannot be null!!");
                                        }

推荐答案

我认为您的Web服务以WSDL文件形式给出.从此WSDL文件自动生成一些Java文件.显然,您的WSDL文件包含一个名为"class"的属性,因此,相应的生成的Java类对该属性具有名为 getClass()的吸气剂.

I take it your web service is given as WSDL file. From this WSDL file some Java files are automatically generated. Apparently, your WSDL file contains a property named "class" and thus the corresponding generated Java class has a getter for this property called getClass().

但是, getClass()是在 Object 类中定义的方法,并且所有Java类都继承自 Object .Java认为您正在尝试重写此方法.这是不允许的,因为1)该方法是最终方法,而2)返回类型不匹配.

However, getClass() is a method which is defined in the Object class and all Java classes inherit from Object. Java thinks you are trying to override this method., which is not allowed, because 1) the method is final, and 2) the return type doesn't match.

您可能想看看这个问题,其中提到了如何重命名属性,以使它的getter与标准Java方法不冲突.

You might want to look at the answer to this question, which mention how you can rename the property so that its getter doesn't conflict with standard Java methods.

这篇关于返回类型与Object.getClass()不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆