Here are two classes from Bruce Eckel's thinking in
JAVA:The first creates a tool package for System.out.println shorthand, the second is to
test the new utility tool by importing the package.
//: com:bruceeckel:tools:P.java
// The P.rint & P.rintln shorthand.
package com.bruceeckel.tools;
public class P {
public static void rint(
String s) {
System.out.print(s);
}
public static void rintln(String s) {
System.out.println(s);
}
} ///:~
//: c05:ToolTest.java
// Uses the tools library.
import com.bruceeckel.tools.*;
public class ToolTest {
public static void main(String[] args) {
P.rintln("Available from now on!");
P.rintln("" + 100); // Force it to be a String
P.rintln("" + 100L);
P.rintln("" + 3.14159);
}
} ///:~
My question is: After I successfully compiled the first class with "javac -d c:\jdk1.3\jre\classes P.java". The second class won't compile because the compiler doesn't recognize method rintln. But when I change the import statement to "import com.bruceeckel.tool.P", the second class runs without any complaints. This seems weird to me because I think the wildcard "*" should be able to represent "P". Bruce mentioned a lot about classpath in his book, but I think Java2 simplified the package creation. Can someone clear this up for me?