[#0x0011] extends interface

  一个imp class可以同时实现多个interface,格式如下:

class Impl implements Intf1,  Intf2, ..., IntfN;

  

  如果一个class又有继承又有实现,那么应该先extends再implements,如:

class ImplExt extends Base implements Intf;

  

  Java中不支持class的多重继承,但interface可以,如:

class Ext extends Base1, Base2, ..., BaseN; //syntax error
interface ExtIntf extends BaseIntf1, BaseIntf2, ..., BaseIntfN; //OK

 

import UIAbility from &#39;@ohos.app.ability.UIAbility&#39;; import hilog from &#39;@ohos.hilog&#39;; import window from &#39;@ohos.window&#39;; import type Want from &#39;@ohos.app.ability.Want&#39;; // 定义可索引对象类型,避免使用 unknown interface StringMap { [key: string]: Object; } /** * 提取错误信息的安全函数 * 不使用 for...in, in, call, apply, prototype, unknown */ function getErrorMessage(error: Object): string { if (error === null) return &#39;null error&#39;; if (error === undefined) return &#39;undefined error&#39;; // 强制转换为字符串键值对对象 const obj = error as StringMap; const message = obj.message; if (typeof message === &#39;string&#39; && message.length > 0) { return message; } const name = obj.name; if (typeof name === &#39;string&#39; && name.length > 0) { return name; } // 最后备选 try { return String(error); } catch (e) { return &#39;Unknown error&#39;; } } export default class EntryAbility extends UIAbility { onCreate(want: Want, launchParam: Object): void { hilog.info(0x0000, &#39;EntryAbility&#39;, &#39;onCreate&#39;); } onDestroy(): void { hilog.info(0x0000, &#39;EntryAbility&#39;, &#39;onDestroy&#39;); } onWindowStageCreate(windowStage: window.WindowStage): void { hilog.info(0x0000, &#39;EntryAbility&#39;, &#39;onWindowStageCreate&#39;); windowStage.loadContent(&#39;pages/Index&#39;) .then(() => { hilog.info(0x0000, &#39;EntryAbility&#39;, &#39;Load page success&#39;); }) .catch((err: Object) => { const errorMsg = getErrorMessage(err); hilog.error(0x0000, &#39;EntryAbility&#39;, &#39;Load page failed: %{public}s&#39;, errorMsg); }); } } Indexed signatures are not supported (arkts-no-indexed-signatures) <ArkTSCheck>
09-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值