接口和实现Java

时间:2018-11-22 11:37:28

标签: java interface

在此链接1中,我有一些接口,我想实现它们。我有一个问题,因为我根据UML的关系有一个IanaRecord数组,但是IanaRegistry接口的查找方法签名会返回 IanaBaseRecord 数组。

因此,当我尝试实现 find 方法时,出现错误,因为当我找到所需的对象时,无法将IanaRecord对象“复制”到IanaBaseRecord对象,以返回IanaBaseRecord列表。

I have uploaded the code with the error I have mentioned

....
public class IanaRegistryImpl implements IanaRegistry{  
private List <IanaRecord> lista = new ArrayList <IanaRecord>();
}
....
public Set<IanaBaseRecord> find(String recordType, String descriptionSubstr) 
{
    Set <IanaBaseRecord> foundlist = new HashSet<IanaBaseRecord>(); 
        for(int x=0; x<lista.size();x++) {          
        if (lista.get(x).getTipo().equals(recordType) && 
          lista.get(x).getDescription().equals(descriptionSubstr)){         
            foundlist.add(lista.get(x)); //here I have the problem
        }
        }
return foundlist;
}
....

致谢

0 个答案:

没有答案