This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi ,all,I meet a confused compile question today. create two java source file named T1.java and T2.java in the same directory,then comiple them. T1.java
T2.java
compile T1 first ,then compile T2.Nothing exceptions happen. But change
to
in T2.java,a compile error happens.compile messages like these:
Yet ,what's the difference between import p1.* and import p1.T1
EDIT by mw: Broke up really long error message line in code tags. [ October 10, 2006: Message edited by: marc weber ]
"A single-type-import declaration imports a single type by giving its canonical name, making it available under a simple name..." (JLS - 7.5.1) So with import p1.T1; the canonical name is easily resolved, and makes T1 available under its simple name.
But a "type-import-on-demand [i.e. "wildcard"] declaration allows all accessible (�6.6) types declared in the type or package named by a canonical name to be imported as needed." (JLS - 7.5.2) So with import p1.*; the compiler needs to go looking for what you mean by the simple name T1. It starts in the current directory (denoted by "."). And indeed, there is a T1.class in the current directory (p1).
But now the compiler says... bad class file: ./T1.class class file contains wrong class: p1.T1
The compiler is finding T1 in the current directory (./T1). But this considered a "bad class file" because T1 is really in a package called p1, and what the compiler thinks it's found (./T1) isn't matching what that file actually contains (p1.T1).
So the compiler makes a suggestion... Please remove or make sure it appears in the correct subdirectory of the classpath.
Question: Have you started working with "classpath" yet? [ October 10, 2006: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org