【发布时间】:2016-12-19 11:28:57
【问题描述】:
我试图保持代码尽可能通用,这只代表 基本设置。我是一名试图了解接口、类的 Java 初学者 和方法。我确实更改了接口名称和类名称以进行引用 他们更容易。我完全清楚这段代码不会编译。 我正在尝试理解这个概念。
Given 是一个接口,具有一个现有的 InterfaceClass 和另一个类 使用界面。
界面:
public interface IInterface extends Comparable<IInterface>{
String getContent() throws DumbException;
}
类:
public class InterfaceClass implements IInterface{
public String getContent() throws DumbException {
// here I would need a parameter (filepath) to get a file
// and read its content and return the content as string
// however the interface doesn't provide a parameter for this
// method. So how is this done?
}
}
使用方法的类:
public class Frame extends AbstractFrame {
public void setDetails(IInterface details) {
// This is the call I don't understand...
details.getContent();
}
}
我不明白的部分是: details 对象如何为 getContent() 提供任何参数? 我的意思是,除了 IInterface details
之外,我什至没有看到这个对象被定义【问题讨论】:
-
setDetails(IInterface details);) -
我希望我能帮助我被你的困惑弄糊涂了。
标签: java methods parameters interface concept