【发布时间】:2015-09-18 20:13:57
【问题描述】:
我遇到了一段我不完全理解的代码。
在这样的类中创建了一个接口:
public class SomeClass {
public interface SomeInterface{
public String getInfo(String str1, String str2);
}
public static final SomeInterface SomeOtherName = new SomeInterface() {
@Override
public String getInfo(String str1, String str2){
//return something;
}
}
}
然后在另一个类中,他们使用SomeOtherName 调用方法getInfo。我不明白这里发生了什么。老实说,我没有在类中创建接口,然后创建该接口类型的对象,然后覆盖其中的方法。有人可以解释一下这段代码发生了什么,因为我需要对其进行测试。
【问题讨论】:
标签: java class interface overriding