Reputation: 1065
I am using a JTree
, and I am traversing the tree using an Enumerator
.
TreeModel columnTreeModel = columnTree.getModel();
TreeNode columnTreeRoot = (TreeNode) columnTreeModel.getRoot();
Enumeration<TreeNode> columnTreeEnumerator =
((DefaultMutableTreeNode) columnTreeRoot).breadthFirstEnumeration();
I get a warning in the 3rd line in this code. The warning is
The expression of type Enumeration needs unchecked conversion to conform to Enumeration
How do I reslove this warning?
Upvotes: 3
Views: 607
Reputation: 11616
DefaultMutableTreeNode
exists since Java 1.2, Java Generics exists since 1.5. That is why the result of the method breadthFirstEnumeration
does not have a type parameter, it is a "raw" enumeration. Same for the TreeModel
. You could write a parametrized TreeModel
that returns a typed root node so you wouldn't need to cast. But it just wasn't possible at the time Swing was designed.
You can't "resolve" this warning without changing the type (e.g. subclassing). Just set a @SuppressWarnings("unchecked")
annotation (and document why you do so) then the warning will vanish.
Upvotes: 6