【java-Kotlin中的错误“必须不为null”】教程文章相关的互联网学习教程文章

java-Kotlin中的错误“必须不为null”【代码】

我正在尝试获取一个.zip文件中的多个文件.尝试解压缩文件会提供java.lang.IllegalStateException:zis.nextEntry不能为null.如何正确地做呢?@Throws(IOException::class)fun unzip(zipFile: File, targetDirectory: File) {val zis = ZipInputStream(BufferedInputStream(FileInputStream(zipFile)))try {var ze: ZipEntryvar count: Intval buffer = ByteArray(8192)ze = zis.nextEntrywhile (ze != null) {val file = File(targ...

java – 检查null时的惯用Kotlin【代码】

在Java中,我会做这样的事情:class Person {private Record record;public String name() {record().get("name");}private Record record() {if (record == null) {refetch();}return record;}private void refetch() {record = service.doSomething()}}在Kotlin,我有这个等价的代码:class Person(private var record: Record?) {fun name() : String {record().get("name");}private fun record() : Record {record ?: refetch()...

java – 如何在Kotlin中检查List是否包含null?【代码】

我无法理解为什么class Main {private val outputStreams: List<OutputStream>@JvmOverloads constructor(outputStreams: List<OutputStream> = LinkedList()) {if(outputStreams.contains(null)) {throw IllegalArgumentException("outputStreams mustn't contain null")}this.outputStreams = outputStreams} }导致编译错误… Main.kt:[12,26]类型推断失败.应在输入类型(参数类型,接收器类型或预期类型)中提及类型参数T的值.尝试...

android – java.lang.IllegalArgumentException:对于Kotlin和WebView,指定为非null的参数为null【代码】

我试图用自定义HTML字符串填充我的WebView并尝试在未加载时显示进度,并在完成时隐藏它. 这是我的代码:webView.settings.javaScriptEnabled = true webView.loadDataWithBaseURL(null, presentation.content, "text/html", "utf-8", null)webView.webViewClient = object : WebViewClient() {override fun onPageStarted(view: WebView, url: String, favicon: Bitmap) {super.onPageStarted(view, url, favicon)webViewProgressBa...

为什么kotlin lambda反编译为java代码是(Function0)null.INSTANCE【代码】

当我在类中声明一个属性如下:class xx{var b:()->Boolean={false} }然后反编译如下:......public xxx() {this.b = (Function0)null.INSTANCE; }......(Function0)null.INSTANCE代表什么?我认为这将是 :this.b= new Function0() {public final Object invoke() {return false;} };但它没有,为什么? 谢谢!解决方法:反编译器未显示正确的结果:例如使用JD-GUI进行操作时,您会得到:final class xx$b$1 extends Lambda implement...