dougong1031 2016-09-16 19:22
浏览 14
已采纳

在没有类型声明的已实现方法上键入声明

I have an interface like so:

interface A {
    static function from($object): self;
}

In the class that implements the interface:

class B implements A {
    static function from(\C $object): self{ // This is highlighted as an error
        return new self();
    }
}

Can I not declare a type when the interface has not declared a type?

  • 写回答

1条回答 默认 最新

  • down_load1117 2016-09-16 22:10
    关注

    Can I not declare a type when the interface has not declared a type?

    In short: no.

    As per the docs for interfaces (which seem pretty clear to me):

    The class implementing the interface must use the exact same method signatures as are defined in the interface. Not doing so will result in a fatal error.

    If you provided more detail as to why you think you need to do this, we could perhaps give a more helpful answer, but yer just asking a yes/no question, and the answer to that is - as I said - "no".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)