macos install 2.7
macos install 2.7
brew install openssl openssl@1.1 readline sqlite3 xz zlib pyenv
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
pyenv install 2.7.18
Reference
Java to Kotlin migration guides
Java to Kotlin migration guides
String
连接字符串:
Java: “1” + “b”
kotlin: “$a$b”
生成字符串:
Java: StringBuilder
kotlin: buildString() // 底层也是使用StringBuilder
通过集合创建字符串:
Java: Stream API
// Java
List numbers = List.of(1, 2, 3, 4, 5, 6);
String invertedOddNumbers = numbers
.stream()
...
kotlin jvm
kotlin jvm
kotlin多平台开发支持:
Android and iOS (在Alpha阶段)
JVM
JavaScript
Native
Scripting
Comparison to java
Some Java issues addressed in Kotlin:
Null references are controlled by the type system.
No raw types
Arrays in Kotlin are invariant
Kotlin has proper function types, as op...
kotlin reflection
kotlin reflection
dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.20")
}
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
</dependency>
</dependencies>
references
class references
...
kotlin destructuring declarations
kotlin destructuring declarations
val (name, age) = person
被翻译成:
val name = person.component1()
val age = person.component2()
for ((a, b) in collection) { ... }
Reference
kotlin this
kotlin this
To denote the current receiver, you use this expressions:
* In a member of a class, this refers to the current object of that class.
* In an extension function or a function literal with receiver this denotes the receiver parameter that is passed on the left-hand side of a dot.
If this has no qualifiers, it refers to the innermo...
kotlin null safety
kotlin null safety
kotlin中产生NPE的原因:
* 显示调用throw NullPointerException()
* 使用!!调用null引用
* 使用未正确初始化的引用
- a leaking this
- 超类构造函数中使用在子类初始化的open member
* Java集成
- 访问null引用
- java把null添加到kotlin MutableList
- 由外部java 代码
避免使用null:
1. 显示使用if检查null, 变量需要是不可变的(保证使用时变量值不是null), 编译器会跟踪检查信息.
...
468 post articles, 59 pages.