日期:2014-05-20  浏览次数:20630 次

不能转换interface 被实现的类???
做了一个如下的interface

public interface OnlineSystem_Interface {

void storeRecord(String XMLSource, int recId);

String retrieveRecord(int recId);

void setDate(String date, int recId);

void updateRecord(int recId);

String setUpdateDate(String date);

}



然后又做了一个类实现这个interface

public class Adapter implements OnlineSystem_Interface{

。。。。。。。。。。。。。。。。。
}

主类里面生成了如下的interface对象

public class Client {

private OnlineSystem_Interface document;

public Client() {

this.document = new Adapter();

}
}

但是, 请问, 为何this.document = new Adapter();这句报错?
报Type mismatch: cannot convert from Adapter to OnlineSystem_Interface

请指点, 谢谢


------解决方案--------------------
看着好像没错啊
------解决方案--------------------
答:从你现在给出的已有代码来看,这是不可能的.因此:错误肯定是由程序其它地方的代码引起的.
------解决方案--------------------
要不你的Adapter就没有implements接口OnlineSystem_Interface
看看是不是有拼写错误,clean一下,rebuild一下再看
------解决方案--------------------
我的eclipse 没有报错。
------解决方案--------------------
使用的是windows系统不?用资源管理器(win+E)打开你的包结构,展开所有包,,,把类的结构分部情况粘到这里。让大家看下你的包里边的类的分部情况,另外把public class Client这个类的所有代码全部粘在这里来。你给的信息量太少了,不能找到问题。你给的代码如果包引用正确的是,是没错的。。。。
------解决方案--------------------
import com.sun.xml.internal.bind.v2.model.core.Adapter; 

当然会错了,你导入的类是错误的。
------解决方案--------------------
搞定啦,高手还是有的,牛奶也是有的呀!