标签: implements

扩展类并在java中实现接口

interface Bouncable{ } 
interface Colorable extends Bouncable{ } 
class Super implements Colorable{ } 
class Sub extends Super implements Colorable {} // Ok (case -1)
Run Code Online (Sandbox Code Playgroud)

但,

class Sub implements Colorable extends Super {} // error (case -2)
Run Code Online (Sandbox Code Playgroud)

为什么case-2显示编译错误{ expected.为什么?虽然,case-1执行没有错误.

java oop extends implements

17
推荐指数
2
解决办法
6万
查看次数

如何在不使用抽象的情况下强制实现子类中的方法?

我想强制子类实现我母类的实现方法.我看这个Java - 强制实现一个已实现的方法,但我无法将我的母类转换为抽象类.

public class myMotherClass { 

   myMethod {

      ...some code ..

   }

}

public class myClass extends myMotherClass {

   myMethod {

      ... other code ...
   }

}
Run Code Online (Sandbox Code Playgroud)

所以,在这个例子中,我想强制myClass实现myMethod.

对不起我的英语不好...

java methods class abstract implements

16
推荐指数
3
解决办法
2万
查看次数

一个类可以在PHP中实现多少个接口?

我正在寻找一个不难的问题的答案,但我找不到一个类可以实现多少个接口.

这可能吗?

class Class1 implements Interface1, Interface2, Interface3, Interface4 {
   .....
}
Run Code Online (Sandbox Code Playgroud)

对于我发现的所有类似示例,我已经看到一个类只能实现2个接口.但是没有关于我正在寻找什么的任何信息.

php oop interface implements

16
推荐指数
4
解决办法
2万
查看次数

在大型项目上使用接口时出现错误

对于较大的 VBA 项目(40,000 多行代码),我无法正确使用接口,因为应用程序(我主要使用 Excel)会经常崩溃。显然,这是因为代码不能保持编译状态(根据我的理解,VBA 代码被编译为 P 代码,稍后解释)。当 VBA 项目受密码保护时,我主要会得到这种行为。

当我打开托管文档时,调试/编译菜单几乎从不“变灰”:
在此处输入图片说明

文章描述了同样的情况。转至第 2.3 节

例如:
IClass接口:

Option Explicit

Public Property Get SomeProperty() As Double
End Property
Run Code Online (Sandbox Code Playgroud)

Class1

Option Explicit

Implements IClass

Private Property Get IClass_SomeProperty() As Double
    IClass_SomeProperty = 0
End Property
Run Code Online (Sandbox Code Playgroud)

标准模块中的代码:

Option Explicit

Sub TestInterface()
    Dim obj As IClass
    
    Set obj = New Class1
    Debug.Print obj.SomeProperty 'Crashes here on large projects only
End Sub
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,Debug.Print obj.SomeProperty如果项目很小,该行可以正常工作并在“立即”窗口中打印 0。但是,在大型项目中,调用此行时应用程序会崩溃。在IClass_SomeProperty没有达到(记录到文件阐明了这一点)。

正如上面提到的文章,有一些方法可以暂时避免这个问题:

  1. 重新编译解决了问题(并非总是如此),但在下次打开文档时可能会发生崩溃,或者它可能会持续几天(假设文件每天都打开)
  2. When …

vba interface implements

14
推荐指数
1
解决办法
321
查看次数

Delphi接口实现

我希望引用计数应该在接口实现中的外部聚合对象上工作.如果我可以参考另一个例子:实现多个接口的类中的清晰度(替代委托):

这是行为的最小再现:

program SO16210993;

{$APPTYPE CONSOLE}

type
  IFoo = interface
    procedure Foo;
  end;

  TFooImpl = class(TInterfacedObject, IFoo)
    procedure Foo;
  end;

  TContainer = class(TInterfacedObject, IFoo)
  private
    FFoo: IFoo;
  public
    constructor Create;
    destructor Destroy; override;
    property Foo: IFoo read FFoo implements IFoo;
  end;

procedure TFooImpl.Foo;
begin
  Writeln('TFooImpl.Foo called');
end;

constructor TContainer.Create;
begin
  inherited;
  FFoo := TFooImpl.Create;
end;

destructor TContainer.Destroy;
begin
  Writeln('TContainer.Destroy called');//this line never runs
  inherited;
end;

procedure Main;
var
  Foo : IFoo;
begin
  Foo := TContainer.Create;
  Foo.Foo;
end;

begin
  Main; …
Run Code Online (Sandbox Code Playgroud)

delphi interface delphi-2007 implements

13
推荐指数
1
解决办法
9011
查看次数

实现vs在Java中的泛型中扩展

有人能告诉我第一个和第二个代码之间的区别是什么吗?MaxPQ代表优先级队列,它是可以相互比较的"密钥"对象的集合.

代码1:

public class MaxPQ<Key extends Comparable<Key>>{
...
}
Run Code Online (Sandbox Code Playgroud)

代码2:

public class MaxPQ<Key implements Comparable<Key>>{
...
}
Run Code Online (Sandbox Code Playgroud)

第二个代码不能编译,但是对于我来说,为什么在使用泛型时需要扩展而不是实现接口是不直观的.

java generics interface extend implements

12
推荐指数
1
解决办法
5287
查看次数

扩展内部接口?

我有一个简单的问题:

为什么Eclipse会为实现这两个接口而尖叫?

public abstract class Gateway implements IPlayerity, IItemity {
    public interface IPlayerity { ... }
    public interface IItemity { ... }
    // I...ity
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

IPlayerity无法解析为某种类型

java inheritance interface implements

10
推荐指数
2
解决办法
4553
查看次数

你怎么称呼实现接口的类?

假设A类实现接口B; 我们可以将什么称为接口B的A类?是这样的情况,A类是接口B的'子类'(好像B是一个类),还是有一个特殊术语来实现接口,或者没有?

提前致谢

编辑:如果是答案,会接受Alex的回复

oop subclass implements

10
推荐指数
2
解决办法
1828
查看次数

如何实现通用接口的方法?

我有这个界面:

public interface ParsableDTO<T> {
    public <T> T parse(ResultSet rs) throws SQLException;
}
Run Code Online (Sandbox Code Playgroud)

在某种dto类中实现,并在另一个类中实现此方法:

public <T extends ParsableDTO<T>> List<T> getParsableDTOs(String table, 
                                                          Class<T> dto_class) {
    List<T> rtn_lst = new ArrayList<T>();
    ResultSet rs = doQueryWithReturn(StringQueryComposer
            .createLikeSelectQuery(table, null, null, null, true));

    try {
        while(rs.next()) {
            rtn_lst.add(T.parse(rs)); //WRONG, CAN'T ACCESS TO parse(...) OF ParsableDTO<T>
        }
        rs.close();
    } catch (SQLException e) {
        System.err.println("Can't parse DTO from " 
                + table + " at " + dateformat.format(new Date()));
        System.err.println("\nError on " + e.getClass().getName() 
                + ": " + …
Run Code Online (Sandbox Code Playgroud)

java generics methods interface implements

10
推荐指数
1
解决办法
504
查看次数

VS Code 在 php 类中自动生成接口方法?

如何从接口“自动实现”/生成方法到 PHP 类?我想使用VS Code为它

界面 :

interface MyInterface{  public function myMethod($param); }
Run Code Online (Sandbox Code Playgroud)

班级 :

Class MyClass implements MyInterface{
//myMethod should be auto generate by vscode
   public function myMethod($param){

}
}
Run Code Online (Sandbox Code Playgroud)

VS Code 中是否存在此功能?

php methods interface implements visual-studio-code

10
推荐指数
1
解决办法
4778
查看次数