1
Enumeration<DefaultMutableTreeNode> allGenres  = node.children();  

node is a javax.swing.tree.DefaultMutableTreeNode.
This statement works as the enumeration contains all the children of
the node but causes a warning: unchecked conversion.
I can’t figure out the correct syntax to eliminate the warning.

AlessioX
  • 3,167
  • 6
  • 24
  • 40
Harry
  • 51
  • 2

1 Answers1

0

In Java, checked and unchecked conversions are when the generic types do not match on both sides of the assignment: ClassType<T> ct = var.method(); where var.method() returns something of type ClassType instead of ClassType<T>.

The Java API says that node.children() returns an object of type Enumeration, not Enumeration<WhateverTreeNode>. So, you could cast your method call: (Enumeration<WhateverTreeNode>)node.children() if you know for sure what the underlying type is, or you assign the return value to a regular Enumeration (which the javac compiler will still probably complain about).

Most likely, you will have to tell the compiler to ignore those warnings because of how the underlying javax code is written.

This related question and the Oracle Java Tutorial on Raw Types might help you understand checked and unchecked conversions.

Community
  • 1
  • 1
callyalater
  • 3,102
  • 8
  • 20
  • 27
  • Another observation: the children of a `DefaultMutableTreeNode` are of type `MutableTreeNode`, not _necessarily_ `DefaultMutableTreeNode` (though OP may have implemented entirely using `DefaultMutableTreeNode`). – Erick G. Hagstrom Feb 15 '16 at 19:25