1

I have setup a small project, with a small final class ByteBufferGuard in a ByteBufferGuard.java file:

final class ByteBufferGuard {
    @FunctionalInterface
    static interface BufferCleaner {
        void freeBuffer(String resourceDescription, ByteBuffer b) throws IOException;
    }
}

And then another class, MMapDirectory.java. Well, in this class I can't refer to BufferCleaner simply by importing it, because this:

import ByteBufferGuard.BufferCleaner;

returns:

cannot resolve symbol ByteBufferGuard

But it's strange because only ByteBufferGuard is marked red, it does see, instead, what comes next, that is BufferCleaner.

Both classes are located under the same gradle default root package, that is src/main/java/

Looking at similar answers, I already tried to "invalidate caches/restart" and also delete .idea folder and open the project again.. no success so far.

Let's say this is not a blocker, because I can substitute all the references of BufferCleaner with ByteBufferGuard.BufferCleaner, but still it bothers me, so I'd like to solve this issue.

Do you know what could be the problem?

java 1.8 u112

intellij 2017.1 eap

Another interesting fact, is that the very same import using Kotlin works like a charm..

elect
  • 6,765
  • 10
  • 53
  • 119

2 Answers2

1

Do not use the default package (unnamed package) - if you move both files to a package (subdirectory) it should work.

package some.package;

final class ByteBufferGuard {
    @FunctionalInterface
    static interface BufferCleaner {
        void freeBuffer(String resourceDescription, ByteBuffer b) throws IOException;
    }
}

and

package some.package;

import some.package.ByteBufferGuard.BufferCleaner;

public class MapDirectory {
    private BufferCleaner cleaner;
    // ...
}

(tested with eclipse, but should be the same)

It is not possible to import classes from the default package:

Community
  • 1
  • 1
user85421
  • 28,957
  • 10
  • 64
  • 87
0

Maybe make your class public, or if You want to be a package, make sure, other class who use ByteBufferGuard is in the same package

MatWdo
  • 1,610
  • 1
  • 13
  • 26