"超级"问题:"错误:'('预期的" [英] "Super" issue: "error: '(' expected"

查看:126
本文介绍了"超级"问题:"错误:'('预期的"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,阅读的感谢!

我用为读取一个ArrayList中的每个对象,并要检查返回每个对象的函数的getType()字符串,它存在于扩展的类的对象。

 的for(int i = 0; I< cat.items.size();我++)
        {
            如果(cat.items.get(ⅰ).super.getType()等于(类型)。);
            {

不过,我得到的错误

  MainApp.java:17:错误:'('预期
如果(cat.items.get(ⅰ).super.getType()等于(类型)。);
                           ^

我觉得我不用户超级正确。你可以提供一个替代?

再次感谢!


解决方案

  

可以为您提供替代?


假设的getType 是由类或suberclass实现,那么这是使用它的方式:

  cat.items.get(I).getType()。等于(型)

请注意,如果子类覆盖在超实施的getType()方法,上面会调用该方法的子类版本。您不能调用超类中重写的方法 1


1 - 嗯...不在此例。而重写方法可以调用 super.getType(),但只能对目标对象进行;即本。它并不适用于你的例子。

Hello and thanks for reading!

I use a "for" to read every object in an arraylist, and want to check the string that returns the function getType() for each object, which exists in the extended class of the objects.

for(int i=0; i<cat.items.size(); i++)
        {
            if ( cat.items.get(i).super.getType().equals(type) );
            {

However, I get the error

    MainApp.java:17: error: '(' expected 
if ( cat.items.get(i).super.getType().equals(type) );
                           ^

I think that I don't user "super" correctly. Can you offer an alternative?

Thanks again!

解决方案

Can you offer an alternative?

Assuming that getType is implemented by the class or a suberclass, then this is the way to use it:

  cat.items.get(i).getType().equals(type)

Note that if the subclass overrides a getType() method that is implemented in the superclass, the above will call the subclass version of the method. You can't call the overridden method in the superclass1.


1 - Well ... not in this case. An override method can call super.getType(), but that can only be done for the target object; i.e. "this". It doesn't apply to your example.

这篇关于&QUOT;超级&QUOT;问题:&QUOT;错误:'('预期的&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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