Java Reference
In-Depth Information
void processValues(String[] names, Lookup table) {
for (int i = 0; i < names.length; i++) {
Object value = table.find(names[i]);
if (value != null)
processValue(names[i], value);
}
}
A class can implement as many interfaces as you choose. This example
implements Lookup using a simple array (methods to set or remove val-
ues are left out for simplicity):
class SimpleLookup implements Lookup {
private String[] names;
private Object[] values;
public Object find(String name) {
for (int i = 0; i < names.length; i++) {
if (names[i].equals(name))
return values[i];
}
return null; // not found
}
// ...
}
An interface can also declare named constants that are static and final .
Additionally, an interface can declare other nested interfaces and even
classes. These nested types are discussed in detail in Chapter 5 . All the
members of an interface are implicitly, or explicitly, public so they can
be accessed anywhere the interface itself is accessible.
Interfaces can be extended using the extends keyword. An interface
can extend one or more other interfaces, adding new constants or new
 
Search WWH ::




Custom Search