Write a tree class in Java where each level has a unique object type
Posted
by
user479576
on Stack Overflow
See other posts from Stack Overflow
or by user479576
Published on 2011-01-05T00:51:13Z
Indexed on
2011/01/05
0:53 UTC
Read the original article
Hit count: 132
I need to write a tree class in Java where each level has a unique object type. The way it is written below does not take advantage of generics and causes alot of duplicate code. Is there a way to write this with Generics ?
public class NodeB {
private String nodeValue;
//private List<NodeB> childNodes;
// constructors
// getters/setters
}
public class NodeA {
private String value;
private List<NodeB> childNodes;
// constructors
// getters/setters
}
public class Tree {
private String value;
private List<NodeA> childNodes;
// constructors
// tree methods
}
© Stack Overflow or respective owner