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).
Toni Epple wrote an approachable explanation of the Netbeans Lookup here:
The community wiki also has a good introduction to the Lookup concept and API:
http://wiki.netbeans.org/AboutLookup
And so does the Netbeans Developer FAQ:
http://wiki.netbeans.org/DevFaqLookup
These all provide explanations, code samples, and links to further resources. They're very useful in comprehending the Lookup API documentation itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.