我在Netbeans IDE 6.9中创建了一个项目
在一个项目中,我有一个IBusinessLogic接口
在第二个项目中,我创建了一个实现IBusinessLogic的BusinessLogic类
在第三个项目中,我创建了一个BusienssLogic对象,并将此对象分配给IBusinessLogic的引用。写作时我没有收到任何错误
我清理并构建第三个项目我得到以下例外:
incompatible types found : com.abc.businesslogic.BusinessLogic required: com.abc.businesslogic.interfaces.IBusinessLogic com.abc.businesslogic.interfaces.IBusinessLogic logic = bl; Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: Some input files use unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 1 error D:\ProjectsFeb12\Service\nbproject\build-impl.xml:531: The following error occurred while executing this line: D:\ProjectsFeb12\Service\nbproject\build-impl.xml:261: Compile failed; see the compiler error output for details. BUILD FAILED (total time: 3 seconds)
我知道我可以在超类型引用中分配子类型的对象,那么此异常必须是IDE。我怎么解决这个问题? 我把所有代码都移到了一个新项目中,但没有用。
代码:
package com.abc.workerhandlers; import com.abc.businesslogic.BusinessLogic; import com.abc.businesslogic.interfaces.IBusinessLogic; public class MQ2MQWorker1 { MQ2MQWorker1(){} public void init(){ BusinessLogic bl = new BusinessLogic(); IBusinessLogic logic = bl; // This line is giving problem } }
当我运行项目时,它执行得很完美,但项目的jar不会在dist目录中创建。
答案 0 :(得分:0)
你确定类路径中有正确的类吗?顺便说一句, 你不应该写
BusinessLogic bl = new BusinessLogic();
IBusinessLogic logic = bl; // This line is giving problem
,而只是IBUsinessLogic logic = new BusinessLogic();