1

I have an interface & its implementation class in the same package. I using javac in commandline to compile them. I am able to compile the interface class successfully, but when try to compile the implementation class after compiling the interface class, I get the error - Symbol not found. However, as both the interface & its implementation are in the same folder, if I do a Javac *. I am able to compile both of them .

Can someone help me understand this behaviour ? Thanks for your time

2
  • Can you clarify a bit ? You say that you cannot "compile the implementation class after compiling the interface class", but it works if you "do a Javac". "Doing a javac" is what most people would call "compiling the class". So can you give us the actual command lines you are using ? Commented Dec 30, 2009 at 9:32
  • It might help to show exactly what commands you are typing, and the exact full text of the error message(s). Commented Dec 30, 2009 at 9:32

2 Answers 2

5

The Java compiler looks for packages by way of a file name convention, a.b.c.Interface is interpreted as look for the interface in a/b/c/Interface.class

If you run javac from the root of your classpath, the compiler will find your interface. I.e. If your package is at D:\sources\a\b\c, start javac in D:\sources and compile a\b\c\Impl.java

Sign up to request clarification or add additional context in comments.

Comments

1

You must compile both files at the same time or add the .class file of the first run in the classpath of javac. javac doesn't try to be smart and doesn't search your harddisk for files which might resolve missing symbols. If you don't pass something in, it won't find it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.