kotlin open
时间: 2023-08-15 22:15:13 浏览: 102
Kotlin中文文档
在Kotlin中,关键字"open"用于打破默认的final限制,允许类和类中的方法可以被继承和重写。在Kotlin中,默认情况下,所有的类和方法都是final的,不能被继承和重写。因此,如果想要在Kotlin中继承父类或者重写方法,需要在类名或者方法名前添加"open"关键字。例如,可以使用"open"关键字来声明一个可被继承的类:open class BaseActivity : AppCompatActivity() {},或者声明一个可被重写的方法:open fun setRootView(view: ViewGroup) {}。\[1\]\[2\]\[3\]
#### 引用[.reference_title]
- *1* [Kotlin 18. Kotlin open 关键字与类名、函数名和变量名的使用](https://blog.csdn.net/zyctimes/article/details/127814613)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [kotlin 中的open关键字](https://blog.csdn.net/weixin_42600398/article/details/114486754)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [kotlin修饰符、open与final](https://blog.csdn.net/sinat_31057219/article/details/90146721)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文