0

I am programming a caching system which can store any object. I have these two classes:

public class Cache<T> { ... }

public class CacheDriver<T> { private Cache<T> cache1, cache2; }

I also have a Test class which contains my main method and the testing code.

public class Test { CacheDriver<String> c; }

When I try to compile from the command line with

javac Test.java

I get this:

Test.java:8: error: cannot find symbol
private CacheDriver<String> c;
        ^
symbol:   class CacheDriver
location: class Test

I also have the same errors when I instantiate CacheDriver objects with:

c = new CacheDriver(Integer.parseInt(args[0]), Integer.parseInt(args[1]));

I've done a little research and think it may have something to do with my generic T and the two classes not sharing the same one, but I don't know how to fix that. How do I do it?

EDIT: I they were inside of a package. I moved them form the package directly to the src folder and it worked. Not exactly sure why, but I'll take it.

Phillip
  • 1
  • 1
  • 1
    Assuming all the classes are in the same package (directory), try `javac *.java`. It's probably that you're trying to compile `Test.java` before the others are built. See also [What does a “Cannot find symbol” or “Cannot resolve symbol” error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – SDJ Jan 20 '20 at 21:25
  • If files `Test.java` and `CacheDriver.java` are located in different folders, then you probably need to specify `-cp` in order to compile, like `java -cp folder1 Test.java`, where `folder1` is the folder containing `CacheDriver.class`. – Daniele Jan 20 '20 at 21:33

0 Answers0