以下
- void print();
- };
- class AC{
- };
-
这时候,AI和AC是独立存在,AC不会因为没有和AI建立关系而编译错误,将AC做以下修改后,AI才和AC建立了关系,AC必须实现AI中声明的方法才能通过编译。
- class AC implement AI{
- void print(){
- system.out.println('Hello World');
- }
- };
- @protocol A
- @end
- @interface
- A : NSObject<A>
- -(void) test:(id<A>) obj;
- @end
- 注意这里的 -(void) test:(id<A>) obj; 这表明test方法接受一个任意类型的对象做为参数,但是该参数对象必须实现接口A,类似于java中的 void test(List<A> obj) 。