Compilation Error: “The modifier 'public' is not valid for this item” while explicitly implementing the interface

后端 未结 5 1530
遥遥无期
遥遥无期 2020-12-02 16:33

I am getting this error while creating a public method on a class for explicitly implementing the interface. I have a workaround: by removing the e

5条回答
  •  误落风尘
    2020-12-02 17:17

    You cannot use access modifiers when implementing interface explicitly. Member will be binded to the interface anyway, so it is no need to specify access modifier, because all interface members are always public, also all explicitly implemented members can be accessed only through member of interface type (see statichippo's answer for example).

提交回复
热议问题