Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Now, remove the public access from the EmptyIntList class. By default, a class is "package-private", i.e., it is known within the package, but not from outside.  Try to compile again.  You should see a few error messages saying that you can't use EmptyIntList.java because it is not public. This is because the TestEmptyIntList class is not part of the funList package. One way to resolve this problem by making TestEmptyIntList part of the funList package. A class of a package can access all the classes (public or "package-private") in the package. However this is not a good solution in general because a client may be using many classes from different packages, but no class can be part of more than one package. For now, just make EmptyIntList.java public again, and recompile TestEmptyIntList.java . You should get no error. Try to run Test_List.java now by click the Test button in DrJava.

Java Generics

Please refer to the Lecture 30 notes.   Also, download and open the contained DrJava project inlec30_code.zip .

Practice writing some visitors using generics:

  1. Forward accumulation sum of a list of integers.
  2. Concatenate, with spaces in between, all the elements of a list of Strings.
  3. A single ToString visitor class that could be used to create instances that could then be used on any given type of list.

DrJava Projects

Here's some more information on using DrJava's project capabiltiies:
DrJavaprovides a utility called Project as a way to manage large Java programs with many files and many packages. We will illustrate the use of DrJavaProject by writing a few visitors for the funlist package.

...