惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
The Hacker News
The Hacker News
O
OpenAI News
TaoSecurity Blog
TaoSecurity Blog
Google DeepMind News
Google DeepMind News
Forbes - Security
Forbes - Security
Spread Privacy
Spread Privacy
SecWiki News
SecWiki News
V
Vulnerabilities – Threatpost
Latest news
Latest news
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
Cloudbric
Cloudbric
Webroot Blog
Webroot Blog
G
Google Developers Blog
M
MIT News - Artificial intelligence
Cisco Talos Blog
Cisco Talos Blog
Blog — PlanetScale
Blog — PlanetScale
Attack and Defense Labs
Attack and Defense Labs
aimingoo的专栏
aimingoo的专栏
The Register - Security
The Register - Security
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
Simon Willison's Weblog
Simon Willison's Weblog
N
News and Events Feed by Topic
L
LINUX DO - 热门话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Jina AI
Jina AI
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Hacker News: Ask HN
Hacker News: Ask HN
有赞技术团队
有赞技术团队
N
Netflix TechBlog - Medium
H
Heimdal Security Blog
L
Lohrmann on Cybersecurity
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
C
CERT Recently Published Vulnerability Notes
Hugging Face - Blog
Hugging Face - Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
T
The Exploit Database - CXSecurity.com
A
About on SuperTechFans
博客园 - 叶小钗
博客园_首页
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
F
Fortinet All Blogs
博客园 - 聂微东

Kotlin

compose 使用性能问题 - V2EX 有人在项目里面使用 compose 开发吗 - V2EX 大家会在老项目中使用 kotlin 吗 - V2EX Kotlin 中文文档 2.2.20 版翻译完成了 - V2EX Kotlin 中文文档 2.1.20 版翻译完成了 - V2EX Kotlin 中文文档 2.1.0 版翻译完成了 - V2EX Kotlin 中文文档 2.0.20 版翻译完成了 - V2EX MIUI API28+ActivityTransition API+kotlin 无法检测到活动,只能手动触发广播,怎么定位问题? - V2EX 我老人家翻译的 Kotlin 中文文档,正在更新到最新的 2.0.20 版 - V2EX 我老人家翻译的《Kotlin 语言参考文档》中文版,已经迁移到了新的 Writerside 环境 - V2EX kotlin 没有受检异常真太难顶了。吐槽 - V2EX 屎山代码一则 - V2EX Kotlin 2.0.0 正式版发布了 - V2EX kotlin 中的 select 到底可以 select 哪些内容啊? - V2EX 请大佬帮忙看一眼我这个注解为什么没能抑制 never used 警告? - V2EX 我老人家翻译的《Kotlin 语言参考文档》中文版 - V2EX 使用 compose 开发了讯飞星火认知模型桌面端应用 - V2EX Kotlin 的协程到底是用来干嘛的?为什么没有可 suspend 的异步 IO 函数? - V2EX Kotlin 协程 Coroutine 与 Spring Boot 项目整合的最佳实践是怎样的? - V2EX 谷歌出品 kotlin 入门教程 - V2EX kotlin 源代码数据集 - V2EX KMM 中目前最成熟,最推荐的 shared viewmodel 方案是什么. - V2EX ​ Java /kotlin AST 构建相关,悬赏 200 求解,人已经麻了 - V2EX 有没有 Kotlin 讲协程比较好的书籍或博客连载 - V2EX ArrayList.set 提示 第二个参数 element 类型是 NoThing ? - V2EX 哪些公司后端用 kotlin 写的 - V2EX kotlin 表达式引擎 - V2EX 最近在看 Kotlin 别人一些代码, 看到如下的代码惊呆了 - V2EX Kotlin 的协程是真协程吗?被 b 站博主搞蒙了 - V2EX 有没有人能帮我解释一下,这里面的代码.如果我创建一个新窗口,按照这个逻辑,怎么显示出来 - V2EX 怎么解决 public reified 函数会要求所有用到的依赖都是 public 的问题 - V2EX Result 的方式处理异常用的多吗,我看了下好像和比较受好评的 rust result 用法差不多 - V2EX Kotlin 更换了新 logo:更加立体、更加清晰 - V2EX Kotlin 1.5.20 发布了~快来看看新特性 - V2EX 关于 kotlin 处理多个可空类型的变量的问题 - V2EX 求解这个 eval 函数返回值为什么是个 lambda?怎么才能拿到值? ​​​ - V2EX kotlin lazy 形式的 grouping and mapping 应该怎么写, sequence 里 grouping + aggregate 怎么比 Java stream 还复杂得多 - V2EX 强大的 v2ex,大家擅长 Kotlin, webview 交互的伙伴,来一波 - V2EX springboot kotlin 和 Java 混编, json 序列化用哪个比较好 - V2EX 有哪些知名 iOS 应用是纯 Kotlin 开发的? - V2EX [协程递归问题请教] - V2EX kotlin 打包问题 - V2EX 求推荐 kotlin 安卓开发教程 - V2EX Kotlin 1.4 Released - V2EX 请教一下 kotlin json 序列化及配合 data class 的正确姿势 - V2EX 各位公司项目后端有用 Kotlin + Spring 的吗, DB 层框架选用的什么? - V2EX 慌的一批, Kotlin 这么优雅的语言为什么不火呢 - V2EX 初入 kotlin,源码找不见求教 - V2EX libcore.reflect.parameterizedtypeimpl cannot be cast to Java .lang.clas 这个错误 我真是莫名其妙 - V2EX
Kotlin 如何检测所有 lateinit 的 field 是否初始化 - V2EX
fanck0605 · 2020-07-07 · via Kotlin

我也是刚写 Kotlin,比较看中 Kotlin 的对空值的处理,还有协程。

@aabbcc112233
如果使用了可空类型,那么以后的调用都要加 `!!`,虽然可以从代码层面控制这些 成员变量 非空,但是这似乎让代码变得不够优雅了。

@holmesabc @dcalsky
这么写的确可以判断单个 成员变量 ,编译时,成员变量 也是固定的,一个一个判断也不是不可以。
但成员变量很多时,写出来的代码似乎就会很冗长。

现在我是这么写的,不知道有没有优化的余地。
```
class Car {

lateinit var field1: String
lateinit var field2: String
lateinit var field3: String
lateinit var name: String
lateinit var color: String

// 这里还有很多成员变量

companion object {
val memberProperties = Car::class.memberProperties

fun parse(text : String): Car {

val car = Car()

// 这里解析一些文本,并初始化 car 的成员变量
// var car.field1 = xxx
// var car.field2 = xxx
// var car.field3 = xxx

// 检测是否都被初始化
for (memberProperty in memberProperties) {
try {
memberProperty.get(car)
} catch (e: UninitializedPropertyAccessException) {
// 抛出异常,保证外部获得的对象,所有变量都被 initialized
throw Exception("${memberProperty.name} is uninitialized! Failed to parse text: $text")
}
}
return car
}
}
}
```