这是我的实际代码:
public TerminalGui[] getTerminalGuis() {
Components comps[] = this.getComponents();
int i, j = 0;
for( i = 0; i < comps.length ; i++ ) {
if( comps[i] instanceof TerminalGui ) {
j++;
}
}
TerminalGui terminalGuis[j];
int k = 0;
for( Component c : comps ) {
if( c instanceof TerminalGui ) {
terminalGuis[k] = c;
k++;
}
}
return terminalGuis;
}
如何做得更好?我想获取所有作为(接口)this.getComponents()
实例的对象。TerminalGui