java - Generify class because of unchecked casting warning -
i have following class methods marked unchecked give me warning. compile/work fine interested if there way generify class intellij idea offering me (but unable do) remove warnings.
public abstract class attribute { private final attributednode containernode; private boolean computationcomplete; public attribute(attributednode node) { this.containernode = node; this.computationcomplete = false; } public attributednode getcontainernode() { return containernode; } public attribute getattributefromchildnode(int childindex, attributenameenum attributename) { attributednode node = getcontainernode().getchild(childindex); return node.getattribute(attributename); } public string getchildnodetext(int index) { return getcontainernode().getchild(index).gettext(); } @suppresswarnings("unchecked") public <t, e extends attribute> list<t> getlistofchildattributevalues(attributenameenum name) { list<t> result = new linkedlist<>(); (attributednode node : this.getcontainernode().getchildren()) { e attribute = (e) node.getattribute(name); result.add((t) attribute.getvalue()); } return result; } public <t extends attribute> object getattributevaluefromcontainer(attributenameenum name) { return this.<t>getattributevaluefromnode(name, this.getcontainernode()); } public <t extends attribute> object getattributevaluefromparent(attributenameenum name) { return this.<t>getattributevaluefromnode(name, this.getcontainernode().getparent()); } @suppresswarnings("unchecked") public <t extends attribute> object getattributevaluefromnode(attributenameenum name, attributednode node) { t attribute = (t) node.getattribute(name); return attribute.getvalue(); } // other methods eluded
p.s. apologize ahead of time of maybe lack of understanding generics.
Comments
Post a Comment