red5 中
public interface IScope extends IBasicScope, ResourcePatternResolver,
IServiceHandlerProvider {
...
}
public interface IBasicScope extends ICoreObject, IEventObservable,
Iterable<IBasicScope>, IPersistable {
...
public String getName();
...
}public String appStart(IScope app){
return app.getName(); //出错
}
这是为什么啊?java第一次用.哪位高手帮我一下.
public interface IScope extends IBasicScope, ResourcePatternResolver,
IServiceHandlerProvider {
...
}
public interface IBasicScope extends ICoreObject, IEventObservable,
Iterable<IBasicScope>, IPersistable {
...
public String getName();
...
}public String appStart(IScope app){
return app.getName(); //出错
}
这是为什么啊?java第一次用.哪位高手帮我一下.
接口之间的继承可以使用多继承, 而类之间的继承只能是单继承。
类虽然只能是单继承, 但是一个类可以实现多个接口。public class Test01 implements C {
public void print() {
System.out.println("Print");
}
public void func() {
System.out.println("Func");
} public static strictfp void main(String args[]) {
Test01 t = new Test01();
t.print();
t.func();
}}interface A {
void func();
}interface B {
void print();
}interface C extends A, B {
}
public class Application extends MultiThreadedApplicationAdapter
{
public String appStart(IScope app){
return app.getName(); //出错
} ...
}
在eclipse 中提示错误,我用IScope接口中的方法就没有问题,用IBaseScope中的方法就提示错误,IScope 应该继承了IBaseScope中的所有的public的方法。可是为什么eclipse会提示错误呢?难道我理解的是错误的?
public void print() {
System.out.println("Print");
}
public void func() {
System.out.println("Func");
} public static strictfp void main(String args[]) {
Test01 t = new Test01();
t.print();
t.func();
}}interface A {
void func();
}interface B {
void print();
}interface C extends A, B {
}
public void print() {
System.out.println("Print");
}
public void func() {
System.out.println("Func");
} public static strictfp void main(String args[]) {
Test01 t = new Test01();
t.print();
t.func();
}}interface A {
void func();
}interface B {
void print();
}interface C extends A, B {
}
public void print() {
System.out.println("Print");
}
public void func() {
System.out.println("Func");
} public static strictfp void main(String args[]) {
Test01 t = new Test01();
t.print();
t.func();
}}interface A {
void func();
}interface B {
void print();
}interface C extends A, B {
}
也就是说。当你用一个类或者借口的引用去调用某个方法的时候编译器首先查看你这个类中是否已经存在这个方法,如果不存在就报错,这就是所谓的静态邦定
比如
一个类A中有个方法b(),然后C类继承类A,按理说C应该拥有b()方法的,但是如果你用new C().b()这样去调用编译肯定通不过的,一定要定义一个A类型的引用,然后把一个C的对象传给A的引用,这样编译期间就认为你是调用A类的b()方法,所以会通过的,但是运行期间因为这个引用指向的是一个C类型的对象,所以当然调用的就是C类中的继承来的b()方法。这就是所谓的动态邦定。
import org.red5.server.api.IBasicScope;
这接口有getName(),可是加进去也报错,到底怎么办啊?...
我也遇到了类似的问题,不知道你不是因为这个。