HarmonyOS interface中如何定义static方法

定义interface的时候,如何约定实现interface的类需要实现的方法为static方法,例如:

interface DemoInterface {
  demoFunction():void;
}

/// DemoClass此时会报错,没有实现demoFunction方法
export public class DemoClass implements DemoInterface {
  static demoFunction():void {

  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
HarmonyOS
2024-12-23 15:09:45
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

interface中是不能添加静态属性(static)和访问修饰符(public、protected、private)的。

分享
微博
QQ
微信
回复
2024-12-23 17:46:10
相关问题
无法从static上下文引用非static方法
10981浏览 • 1回复 待解决
static 方法支持mock吗?
1636浏览 • 1回复 待解决
HarmonyOS 方法里有interface,实现问题
636浏览 • 2回复 待解决
HarmonyOS定义interface回调问题
947浏览 • 1回复 待解决
HarmonyOS 如何遍历interface
592浏览 • 1回复 待解决
HarmonyOS interface 问题
905浏览 • 1回复 待解决
c++侧可以直接调用ts的static方法吗?
3202浏览 • 1回复 待解决
interface如何间接导出
1627浏览 • 1回复 待解决
interface回调如何调用
1440浏览 • 1回复 待解决
数组的map函数, 如何返回interface
861浏览 • 1回复 待解决
HarmonyOS 关于interface的使用
1667浏览 • 1回复 待解决
ets文件怎么调用ts文件定义方法
4127浏览 • 1回复 待解决
如何判断对象是某个interface的实现
1828浏览 • 1回复 待解决