从库中实现接口内部的内部类

时间:2016-07-21 05:26:06

标签: java interface java-8

我有一个实用程序项目,让我们调用它utility-library,其中包含一个具有以下结构的类。

public interface OuterInterfaceI {

    public static class InnerClass {
        // ... a couple of static and non static methods
    }

}

现在,当我尝试在utility-library内执行以下操作时,它编译得很好

OuterInterfaceI.InnerClass innerClassObject;

现在我需要在另一个项目中使用它,所以我将项目的jar utility-library.jar(通过mavent构建)添加到我的项目的构建路径(让我们称之为my-application)。当我尝试在类中编写以下代码时,它无法编译。

import com.utility.commons.OuterInterfaceI;

public class SomeClass {
    private static OuterInterfaceI.InnerClass myObject;
}

编译器失败并显示以下错误消息

The type com.utility.commons.OuterInterfaceI.InnerClass cannot be resolved. It is indirectly referenced from required .class files.

我确保utility-library.jar在类路径上。我缺少什么?

更新

我正在使用Eclipse Version:Mars.1 Release(4.5.1)和maven 3.3.3 with java 1.8.0_45。我认为这可能是eclipse中的一个错误,但是当我尝试从终端构建时,我遇到同一个类的编译时间问题

$ mvn clean test
[INFO] Scanning for projects...
[INFO]                                                                         
.....................
.....................
[INFO] Compiling 90 source files to /home/msamirza/etilize_repo_folders/jdk8_migrations/...................
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com..... :[20,32] error: cannot access InnerClass
[ERROR]   class file for com.utility.commons.OuterInterfaceI$InnerClass not found
/home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com/.....:[25,38] error: cannot find symbol
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.182 s
[INFO] Finished at: 2016-07-21T10:37:57+05:00
[INFO] Final Memory: 19M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project inQuire-Merchandising-Server: Compilation failure: Compilation failure:
[ERROR] /home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com/........:[20,32] error: cannot access InnerClass
[ERROR] class file for com.utility.commons.OuterInterfaceI$InnerClass not found
[ERROR] /home/msamirza/etilize_repo_folders/jdk8_migrations/inQuire/inQuireMerchandising/merch-server-module/src/main/java/com/........:[25,38] error: cannot find symbol
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

0 个答案:

没有答案