Java Reference
In-Depth Information
key concepts
AbstractCollection Implements some of the methods in the Collection inter-
face. (580)
inner class A class inside a class, which is useful for implementing the iterator
pattern. The inner class always contains an implicit reference to the outer
object that created it. (576)
StringBuilder Used to construct String s without repeatedly creating a large
number of intermediate String s. (584)
common errors
An instance inner class cannot be constructed without an outer object.
This is most easily done with a factory method in the outer class. It is
common to forget the word static when declaring a nested class, and this
will often generate a difficult-to-understand error related to this rule.
1.
Excessive String concatenations can turn a linear-time program into a
quadratic-time program.
2.
on the internet
The following files are available:
MyContainerTest.java The test program for the final iterator example
that uses inner classes, as shown in Section
15.2. Iterator.java and MyContainer.java are
both found in the weiss.ds package online.
AbstractCollection.java Contains the code in Figures 15.10 to 15.12.
ArrayList.java
Contains the code in Figures 15.13 to 15.16.
exercises
IN SHORT
15.1
What is the difference between a nested class and an inner class?
Are private members of an inner (or nested) class visible to methods in
the outer class?
15.2
In Figure 15.17, are the declarations of a and b legal? Why or why not?
15.3
 
 
Search WWH ::




Custom Search