【发布时间】:2013-03-14 01:39:07
【问题描述】:
我需要获取容器的所有子文本字段,检票口提供了一个名为visitChildren的方法
然后我会做类似的事情:
(FormComponent<?>[]) visitChildren(TextField.class).toList().toArray();
这个例子不起作用,我得到的异常是:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lorg.apache.wicket.markup.html.form.FormComponent;
但如果我这样做:
List<Component> list = visitChildren(TextField.class).toList();
FormComponent<?>[] array = new FormComponent[list.size()];
for (int x = 0; x < list.size(); x++) {
array[x] = (FormComponent<?>) list.get(x);
}
它有效,为什么会这样?据我所知,这两种方法都应该有效
【问题讨论】:
-
下面的方法是最简单的方法,this answer should 告诉你为什么它不起作用。