“illegal generic type of instanceof” when using instanceof on an inner class type?

a 夏天 提交于 2019-12-05 13:50:01

Try ob instanceof Grafo<?,?>.Par

I think that the compiler thinks that ob instanceof Par involves a runtime check on generic type parameters; i.e. that it is equivalent to ob instanceof Grafo<V,E>.Par. But instanceof tests cannot check generic type parameters.

@SuppressWarnings("unchecked")
@Override
public boolean equals(Object ob)
{
    if(ob instanceof Grafo.Par) {
        Par p = (Par)ob;
        return this.a==p.a && this.b==p.b;
    }

    return false;
}

Or define your inner class static

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!