TreeNode interface

UI Components for JSF
Post Reply
mko
Posts: 4
Joined: 22 Nov 2016, 10:24

31 Mar 2023, 09:52

Hey guys,

I have a question about the TreeNode interface. Here is the relevant code:

Code: Select all

public interface TreeNode<T> {
    T getData();

    List<TreeNode<T>> getChildren();
This implies, that all nodes in the tree have to have the same data type, because the node itself and also the children have the same generic type T. However, this doesn't make any sense to me. The way we are using trees, each level or even each node might have a different data type.

Is this really intended? Can it be changed?

Thank you very much in advance!

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

31 Mar 2023, 13:52

That is correct and the idea is you give it a wrapper object. You nodes may be different types but can't you just differentiate that inside this wrapper object?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

mko
Posts: 4
Joined: 22 Nov 2016, 10:24

31 Mar 2023, 14:02

Thanks for sharing your intentions, that explains the architecture. We're coming from PrimeFaces 7 where the TreeNode was not generic and so we just used different data object types or even different TreeNode implementations interchangably.
We'll have to think about whether to adopt this approach or trust in Java's type erasure :D.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

31 Mar 2023, 17:05

You can also just do TreeNode<Object> ;)
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 38 guests