当前位置:网站首页>十、Kotlin基础学习:1、延迟加载;2、异常处理;3、使用 throw 主动抛出异常;4、自定义异常;
十、Kotlin基础学习:1、延迟加载;2、异常处理;3、使用 throw 主动抛出异常;4、自定义异常;
2022-07-30 05:43:00 【¥伊人独醉】
1、延迟加载;
在变量初始化时,如果变量不访问,就不加载,第一次访问时进行加载。之后不再加载。
语法:
val 变量:类型 by lazy{
变量初始化代码
}
【案例】

日志:
点击两次按钮。
第一次:

第二次:
2、异常处理;
try{
…
} catch {
…
} finally {
…
}
【案例】

MyTest.kt

activity_main.xml
MainActivity.kt

日志:
3、使用 throw 主动抛出异常;
【案例】

MyTest2.kt

修改MainActivity.kt
日志:
4、自定义异常;
定义一个类继承Throwable接口。
【案例】

MyException.kt

Student.kt
MainActivity.kt
日志:
边栏推荐
- Powerhouse Cup Preliminary WP
- Arthas 命令解析(jvm/thread/stack/heapdump)
- MySQL 索引的数据结构及类型
- Mysql 客户端常见异常分析
- 使用kotlin扩展插件/依赖项简化代码(在最新版本4.0以后,此插件已被弃用,故请选择性学习,以了解为主。)
- [Getting C language from zero basis - navigation summary]
- c#下Web3合约空投、转账调用代码
- JVM Learning (2) Garbage Collector
- Detailed introduction to the usage of Nacos configuration center
- [PASECA2019]honey_shop
猜你喜欢

Arrays工具类的使用

SSTI range

c#下Web3合约空投、转账调用代码
![Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc](/img/2d/50c9001125cd613087044d2b6c78b1.png)
Monstache执行monstache -f config.toml出错No processor type exists with name [attachment] [type=parse_exc

Monstache执行Monstache - f配置。toml出错不存在处理器类型和名称(附件)(= parse_exc类型

uni-app: The use of uni-icons and how to customize icons
Go简单实现协程池
Remember a traffic analysis practice - Anheng Technology (August ctf)

uni-app: about custom components, easycom specs, uni_modules, etc.

网上说的挖矿究竟是什么? 挖矿系统开发详解介绍
随机推荐
Detailed explanation of ClickHouse query statement
Solution to TypeError The view function did not return a valid response. The function either returned None
CTFSHOW command execution [web29-web124] unfinished to be continued
Use kotlin to extend plugins/dependencies to simplify code (after the latest version 4.0, this plugin has been deprecated, so please choose to learn, mainly to understand.)
根据ip地址获取地理位置及坐标(离线方式)
学生管理系统
【SQL】SQL 高频面试题英语版(1)
第一个WebAssembly程序
Redis 客户端常见异常分析
vulnhub-XXE ctf security question
Understand JDBC in one article
TDengine cluster construction
21. Kotlin Advanced Learning: Implementing Simple Network Access Encapsulation
使用PyQt5为YoloV5添加界面(一)
mysql不是内部或外部命令,也不是可运行的程序或批处理文件解决
SQL Server Installation Tutorial
MySQL - Function and Constraint Commands
Briefly describe SSRF
"MySQL Advanced Chapter" four, the storage structure of the index
TDengineGUI cannot connect to TDengine