0

In Zk framework when Parent child components hierarchy is there , then when you want to read value of child components do we need to check instanceof xyz. eg (component instanceof Textbox) every time or we have any other option?? instanceof is very hard operation which can cause performance issue.

Rahul Rabhadiya
  • 430
  • 5
  • 19

2 Answers2

0

If all children of a component are of the same type, you can use the generic parameter of Component.getChildren() to avoid casting:

Collection<Textbox> children = parent.<Textbox> getChildren();

It seems that in your case, you have children of various/unknown type. In that case, I do not see how you could avoid checking and casting without keeping references to each child.

Malte Hartwig
  • 4,477
  • 2
  • 14
  • 30
  • Thanks for reply, issue is the case when children of various type are there , at that time you have to use instanceof which is not good I guess. – Rahul Rabhadiya Apr 20 '17 at 09:58
  • You shouldn't worry about a performance impact, instanceof is not slow: http://stackoverflow.com/questions/103564/the-performance-impact-of-using-instanceof-in-java – Malte Hartwig Apr 24 '17 at 09:51
0

If you 100% sure that nth child is instance of xyz, then you just cast it. But unfortunately if you fill parent dynamically, the only way is to check every child.

Sergey
  • 176
  • 2
  • 12