在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):JakeWharton/confundus开源软件地址(OpenSource Url):https://github.com/JakeWharton/confundus开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Confundus: Unsafe Cast for Kotlin/JVMA Kotlin compiler plugin which brings Kotlin/JS's The Okay but why?Sometimes you know more than the compiler. If you know a nullable reference is actually non-null
you can use Both of these are runtime-checked operations. This means that there is bytecode which validates the
conversion. You'll get a When writing performance-sensitive code these runtime checks can sometimes have a prohibitive cost. For example, in a doubly-linked structure, invariants mean that if
With Supported conversionsNullable to non-null type val o1: String? = someFunction()
-val o2: String = o1!!
+val o2: String = o1.unsafeCast<String>() ALOAD 0
- DUP
- IFNONNULL L1
- INVOKESTATIC kotlin/jvm/internal/Intrinsics.throwNpe ()V
-L1
ASTORE 1 Non-null to non-null subtype val o1: Any = someFunction()
-val o2: String = o1 as String
+val o2: String = o1.unsafeCast<String>() ALOAD 0
- DUP
- IFNONNULL L1
- NEW kotlin/TypeCastException
- DUP
- LDC "null cannot be cast to non-null type kotlin.String"
- INVOKESPECIAL kotlin/TypeCastException.<init> (Ljava/lang/String;)V
- ATHROW
-L1
CHECKCAST java/lang/String
ASTORE 1 Note: The Nullable to non-null subtype val o1: Any? = someFunction()
-val o2: String = o1 as String
+val o2: String = o1.unsafeCast<String>() ALOAD 0
- DUP
- IFNONNULL L1
- NEW kotlin/TypeCastException
- DUP
- LDC "null cannot be cast to non-null type kotlin.String"
- INVOKESPECIAL kotlin/TypeCastException.<init> (Ljava/lang/String;)V
- ATHROW
-L1
CHECKCAST java/lang/String
ASTORE 1 Note: The Nullable to nullable subtypeNote: No change in bytecode for this case! val o1: Any? = someFunction()
-val o2: String? = o1 as String?
+val o2: String? = o1.unsafeCast<String?>() ALOAD 0
CHECKCAST java/lang/String
ASTORE 1 Usagebuildscript {
dependencies {
classpath 'com.jakewharton.confundus:confundus-gradle:1.0.0'
}
}
apply plugin: 'org.jetbrains.kotlin.jvm' // or .multiplatform
apply plugin: 'com.jakewharton.confundus' The License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论