• Home
Name Date Size #Lines LOC

..--

AppScope/22-Oct-2025-3532

achievenon/22-Oct-2025-519462

arrowfunctions/22-Oct-2025-513455

cannotbeused/22-Oct-2025-497443

hvigor/22-Oct-2025-3836

inheritedfromnon/22-Oct-2025-510455

inheritonly/22-Oct-2025-569516

nocalculationsupport/22-Oct-2025-518463

notallowedInside/22-Oct-2025-542483

objectliterals/22-Oct-2025-495440

screenshots/22-Oct-2025-

templatetype/22-Oct-2025-505450

typecannot/22-Oct-2025-507451

variablenotsupported/22-Oct-2025-500447

variablesupport/22-Oct-2025-500447

.gitignoreD22-Oct-2025133 1212

README.mdD22-Oct-20257.2 KiB195175

build-profile.json5D22-Oct-20254 KiB190189

code-linter.json5D22-Oct-2025958 3534

hvigorfile.tsD22-Oct-2025843 225

oh-package.json5D22-Oct-2025834 2624

ohosTest.mdD22-Oct-20253.9 KiB2118

README.md

1# ArkTS Sendable使用规则与约束
2
3该工程中展示的代码详细描述可查如下链接:
4
5- [Sendable使用规则与约束](https://docs.openharmony.cn/pages/v5.0/zh-cn/application-dev/arkts-utils/sendable-constraints.md)
6
7### 效果预览
8
9|                                   首页                                    |                            执行及结果即时反馈                             |
10| :-----------------------------------------------------------------------: | :-----------------------------------------------------------------------: |
11| <img src="./screenshots/RulesAndRestrictions_1.png" style="zoom: 50%;" /> | <img src="./screenshots/RulesAndRestrictions_2.png" style="zoom: 50%;" /> |
12
13### 使用说明
14
151. 在主界面中,点击任意功能按钮可跳转至相应页面,随后点击界面显示的文本字符串即可触发程序执行。
162. 执行结果会即时反馈在屏幕中央,并在控制台打印log。
17
18### 工程目录
19
20```
21achievenon/src/
22 ├── main
23 │   ├── ets
24 │   │   ├── achievenonability
25 │   │   ├── pages
26 │   │       ├── Index.ets             // 非Sendable class只能实现非Sendable interface和Sendable装饰器修饰类型时仅支持修饰函数类型
27 │   ├── module.json5
28 │   └── resources
29 ├── ohosTest
30 │   ├── ets
31 │   │   ├── test
32 │   │       ├── Ability.test.ets      // 自动化测试
33arrowfunctions/src/
34 ├── main
35 │   ├── ets
36 │   │   ├── arrowfunctionsability
37 │   │   ├── pages
38 │   │       ├── Index.ets             // 箭头函数不支持共享
39 │   ├── module.json5
40 │   └── resources
41 ├── ohosTest
42 │   ├── ets
43 │   │   ├── test
44 │   │       ├── Ability.test.ets      // 自动化测试
45cannotbeused/src/
46 ├── main
47 │   ├── ets
48 │   │   ├── cannotbeusedability
49 │   │   ├── pages
50 │   │       ├── Index.ets             // Sendable class和Sendable function不能使用除了@Sendable的其它装饰器
51 │   ├── module.json5
52 │   └── resources
53 ├── ohosTest
54 │   ├── ets
55 │   │   ├── test
56 │   │       ├── Ability.test.ets      // 自动化测试
57inheritedfromnon/src/
58 ├── main
59 │   ├── ets
60 │   │   ├── inheritedfromnonability
61 │   │   ├── pages
62 │   │       ├── Index.ets             // 非Sendable class只能继承自非Sendable class
63 │   ├── module.json5
64 │   └── resources
65 ├── ohosTest
66 │   ├── ets
67 │   │   ├── test
68 │   │       ├── Ability.test.ets      // 自动化测试
69inheritonly/src/
70 ├── main
71 │   ├── ets
72 │   │   ├── entryability
73 │   │   ├── entrybackupability
74 │   │   ├── pages
75 │   │       ├── Index.ets             // Sendable class只能继承自Sendable class
76 │   ├── module.json5
77 │   └── resources
78 ├── ohosTest
79 │   ├── ets
80 │   │   ├── test
81 │   │       ├── Ability.test.ets      // 自动化测试
82nocalculationsupport/src/
83 ├── main
84 │   ├── ets
85 │   │   ├── nocalculationsupportability
86 │   │   ├── pages
87 │   │       ├── Index.ets             // Sendable class/interface的成员变量不支持使用计算属性名
88 │   ├── module.json5
89 │   └── resources
90 ├── ohosTest
91 │   ├── ets
92 │   │   ├── test
93 │   │       ├── Ability.test.ets      // 自动化测试
94notallowedInside/src/
95 ├── main
96 │   ├── ets
97 │   │   ├── notallowedinsideability
98 │   │   ├── pages
99 │   │       ├── Index.ets             // Sendable class的内部不允许使用当前模块内上下文环境中定义的变量
100 │   ├── module.json5
101 │   └── resources
102 ├── ohosTest
103 │   ├── ets
104 │   │   ├── test
105 │   │       ├── Ability.test.ets      // 自动化测试
106objectliterals/src/
107 ├── main
108 │   ├── ets
109 │   │   ├── objectliteralsability
110 │   │   ├── pages
111 │   │       ├── Index.ets             // 不能使用对象字面量/数组字面量初始化Sendable类型
112 │   ├── module.json5
113 │   └── resources
114 ├── ohosTest
115 │   ├── ets
116 │   │   ├── test
117 │   │       ├── Ability.test.ets      // 自动化测试
118templatetype/src/
119 ├── main
120 │   ├── ets
121 │   │   ├── templatetypeability
122 │   │   ├── pages
123 │   │       ├── Index.ets             // 泛型类中的Sendable class,collections.Array/Map/Set的模板类型必须是Sendable类型
124 │   ├── module.json5
125 │   └── resources
126 ├── ohosTest
127 │   ├── ets
128 │   │   ├── test
129 │   │       ├── Ability.test.ets      // 自动化测试
130typecannot/src/
131 ├── main
132 │   ├── ets
133 │   │   ├── typecannotability
134 │   │   ├── pages
135 │   │       ├── Index.ets             // 非Sendable类型不可以as成Sendable类型
136 │   ├── module.json5
137 │   └── resources
138 ├── ohosTest
139 │   ├── ets
140 │   │   ├── test
141 │   │       ├── Ability.test.ets      // 自动化测试
142variablenotsupported/src/
143 ├── main
144 │   ├── ets
145 │   │   ├── variablenotsupportedability
146 │   │   ├── pages
147 │   │       ├── Index.ets             // Sendable class/interface的成员变量不支持使用!断言
148 │   ├── module.json5
149 │   └── resources
150 ├── ohosTest
151 │   ├── ets
152 │   │   ├── test
153 │   │       ├── Ability.test.ets      // 自动化测试
154variablesupport/src/
155 ├── main
156 │   ├── ets
157 │   │   ├── variablesupportability
158 │   │   ├── pages
159 │   │       ├── Index.ets             // Sendable class/interface成员变量必须是Sendable支持的数据类型
160 │   ├── module.json5
161 │   └── resources
162 ├── ohosTest
163 │   ├── ets
164 │   │   ├── test
165 │   │       ├── Ability.test.ets      // 自动化测试
166```
167
168### 相关权限
169
170不涉及。
171
172### 依赖
173
174不涉及。
175
176### 约束与限制
177
1781.本示例仅支持标准系统上运行, 支持设备:RK3568。
179
1802.本示例为Stage模型,支持API14版本SDK,版本号:5.0.2.57,镜像版本号:OpenHarmony_5.0.2.58。
181
1823.本示例需要使用DevEco Studio 5.0.1 Release (Build Version: 5.0.5.306, built on December 6, 2024)及以上版本才可编译运行。
183
184### 下载
185
186如需单独下载本工程,执行如下命令:
187
188```
189git init
190git config core.sparsecheckout true
191echo code/DocsSample/ArkTS/ArkTsConcurrent/ConcurrentThreadCommunication/InterThreadCommunicationObjects/SendableObject/RulesAndRestrictions > .git/info/sparse-checkout
192git remote add origin https://gitee.com/openharmony/applications_app_samples.git
193git pull origin master
194```
195