nbk nbk - 5 months ago 25
Java Question

How do I refer to Java classes in the same directory?

I have an SBT project that has a number of classes declared as java files. Two of them are Table.java and LinHashMap.java. They are both in the
directory. I want to create and refer to a LinHashMap object in the Table class. I thought that since they are in the same directory I don't have to include an import statement. Am I wrong? When I compile I get the error:

[error] src/main/java/cs4370/Table.java:90: cannot find symbol
[error] symbol: class LinHashMap
[error] location: class Table
[error] index = new LinHashMap <> (Comparable [].class, Comparable [].class);

What do I have to do to refer to LinHashMap objects?


You need to declare them as being in the same package :

package mypackage;

Being in the same folder only implies that the compiler will know where to look for the files. Being in the same package is required to not have to use fully specified class name.

That is actually the definition of what 'import' is used for.