...
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 in lec29_code.zip .
Practice writing some visitors using generics:
- Forward accumulation sum of a list of integers.
- Concatenate, with spaces in between, all the elements of a list of Strings.
- 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.
...
- 6. Write a visitor called
ToString
to compute a Scheme-like String representation of the list. (See ListString visitor done in lab 09). Package it infunlist.visitor
. Write stub code only and make sure that everything compiles.- Now write a JUnit test class called
TestToString
to testToString
. Package it in thetest
subdirectory as done in the above step 5. Make sure it compiles. - Incrementally write ToString and incrementally test it until all the test code pass.
- Now write a JUnit test class called
Access Permissions: (Please don't edit)
- Set ALLOWTOPICCHANGE = Main.TeachersComp211Group
...