I am learning how to develop a desktop application based on Netbeans Platform Application, so I have started with the famous Quick start tutorial, I have been blocked to understand that piece of code (Netbeans 8.0 platform developers can get it):
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
String enteredText = text.getText();
Collection<? extends WordFilter> allFilters = Lookup.getDefault().lookupAll(WordFilter.class);
StringBuilder sb = new StringBuilder();
for (WordFilter textFilter : allFilters) {
String processedText = textFilter.process(enteredText);
sb.append(processedText).append("\n");
}
text.setText(sb.toString());
}
What I did not understand and of course it is the reason of an execution problem with my code is the line: Collection allFilters = Lookup.getDefault().lookupAll(WordFilter.class);
Can anyone explain it to me, what lookup
is? and what that way of using Collection
is? (there is no explanation in the tutorial).
Here is the documentation for Lookup class. Please take a look.
The Collection construction means a collection of objects who's classes extend the WordFilter class (or implements the WordFilter interface, in case WordFilter is an interface).