- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从包含来自 Kotlin 上的 android 应用程序的另一个外部依赖项(retro stream)的存储库中实现外部 JAVA 依赖项,结果我遇到了崩溃在 android 5 上由 java.lang.NoSuchMethodError: No static method 根据 JAVA-library 内的跟踪(跟踪附在下面) .问题出现在 retro stream 库的 Stream 类中(方法“of”)。我已经检查过该库是否存在于外部依赖项中,并且所有类和方法都可以从代码中看到,最有趣的是,它不会在 android> = 7 设备上崩溃。
我已经尝试从 kotlin 代码中显式调用方法 - 没问题。
Versions:
Kotlin 1.3.50
Gradle plugin 3.4.2
Gradle 5.4.1
Android studio 3.5
问题代码:
EmptyUtils.getLastNotNullGotValue(Supplier { "" })
E/AndroidRuntime( 5699): FATAL EXCEPTION: main E/AndroidRuntime( 5699): Process: com.jetruby.kotlindslgradleexample, PID: 5699 E/AndroidRuntime( 5699): java.lang.NoSuchMethodError: No static method of([Ljava/lang/Object;)Ljava9/util/stream/Stream; in class Ljava9/util/stream/Stream; or its super classes (declaration of 'java9.util.stream.Stream' appears in /data/app/com.jetruby.kotlindslgradleexample-2/base.apk) E/AndroidRuntime( 5699): at ru.m4bank.mpos.service.network.utils.EmptyUtils.getLastNotNullGotValueOrDefault(EmptyUtils.java:40) E/AndroidRuntime( 5699): at ru.m4bank.mpos.service.network.utils.EmptyUtils.getLastNotNullGotValue(EmptyUtils.java:51) E/AndroidRuntime( 5699): at com.jetruby.kotlindslgradleexample.MainActivity.onCreate(MainActivity.kt:33) E/AndroidRuntime( 5699): at android.app.Activity.performCreate(Activity.java:5990) E/AndroidRuntime( 5699): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106) E/AndroidRuntime( 5699): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278) E/AndroidRuntime( 5699): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) E/AndroidRuntime( 5699): at android.app.ActivityThread.access$800(ActivityThread.java:151) E/AndroidRuntime( 5699): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) E/AndroidRuntime( 5699): at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime( 5699): at android.os.Looper.loop(Looper.java:135) E/AndroidRuntime( 5699): at android.app.ActivityThread.main(ActivityThread.java:5254) E/AndroidRuntime( 5699): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 5699): at java.lang.reflect.Method.invoke(Method.java:372) E/AndroidRuntime( 5699): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) E/AndroidRuntime( 5699): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
在尝试了各种汇编选项后,我发现如果你在本地(通过文件)实现JAVA依赖,在5-th android 上不会崩溃!! 。此外,如果从 JAVA 而不是从 kotlin 编译,则不会发生掉落。它只适用于接口(interface)中的静态方法。
在下图中,有 2 个依赖项变体(第一个是我从 gradle 缓存中复制的,当我拉出第二个并在本地将其实现为 file 时,第二个刚刚从存储库中提取)。
结果:
On android <7: 1-st variant - all ok, 2-nd variant - crashes.
On android >=7 - 1,2 variants - ok
我已经反编译了应用程序并注意到 kotlin 来自接口(interface)的静态方法 被收集在一个单独的类中(辅助内部类 ClassName.CC 被创建并在其中放置了静态方法)。因此,当从存储库实现依赖时,反编译的外部类引用原始类和原始方法,当从本地源实现时> (从拉取的仓库复制到libs文件夹),它指的是辅助XX.CC。怀疑是 java.lang.NoSuchMethodError crashes: No static method 的原因。
Decompiled classes of the problem class
下面的代码是“helper”类的反编译代码,“missing”了方法。成功和不成功的构建都是一样的:
.class public final synthetic Ljava9/util/stream/Stream$-CC;
.super Ljava/lang/Object;
.source "Stream.java"
# direct methods
.method public static $default$dropWhile(Ljava9/util/stream/Stream;Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;
.locals 3
.param p0, "_this" # Ljava9/util/stream/Stream;
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava9/util/function/Predicate<",
"-TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 630
.local p0, "this":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<TT;>;"
.local p1, "predicate":Ljava9/util/function/Predicate;, "Ljava9/util/function/Predicate<-TT;>;"
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 633
new-instance v0, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Dropping;
.line 634
invoke-interface {p0}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;
move-result-object v1
const/4 v2, 0x1
invoke-direct {v0, v1, v2, p1}, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Dropping;-><init>(Ljava9/util/Spliterator;ZLjava9/util/function/Predicate;)V
.line 635
invoke-interface {p0}, Ljava9/util/stream/Stream;->isParallel()Z
move-result v1
.line 633
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v0
.line 635
invoke-static {p0}, Ljava9/util/stream/StreamSupport;->closeHandler(Ljava9/util/stream/BaseStream;)Ljava/lang/Runnable;
move-result-object v1
invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->onClose(Ljava/lang/Runnable;)Ljava9/util/stream/BaseStream;
move-result-object v0
check-cast v0, Ljava9/util/stream/Stream;
return-object v0
.end method
.method public static $default$takeWhile(Ljava9/util/stream/Stream;Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;
.locals 3
.param p0, "_this" # Ljava9/util/stream/Stream;
.annotation system Ldalvik/annotation/Signature;
value = {
"(",
"Ljava9/util/function/Predicate<",
"-TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 564
.local p0, "this":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<TT;>;"
.local p1, "predicate":Ljava9/util/function/Predicate;, "Ljava9/util/function/Predicate<-TT;>;"
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 567
new-instance v0, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Taking;
.line 568
invoke-interface {p0}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;
move-result-object v1
const/4 v2, 0x1
invoke-direct {v0, v1, v2, p1}, Ljava9/util/stream/WhileOps$UnorderedWhileSpliterator$OfRef$Taking;-><init>(Ljava9/util/Spliterator;ZLjava9/util/function/Predicate;)V
.line 569
invoke-interface {p0}, Ljava9/util/stream/Stream;->isParallel()Z
move-result v1
.line 567
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v0
.line 569
invoke-static {p0}, Ljava9/util/stream/StreamSupport;->closeHandler(Ljava9/util/stream/BaseStream;)Ljava/lang/Runnable;
move-result-object v1
invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->onClose(Ljava/lang/Runnable;)Ljava9/util/stream/BaseStream;
move-result-object v0
check-cast v0, Ljava9/util/stream/Stream;
return-object v0
.end method
.method public static builder()Ljava9/util/stream/Stream$Builder;
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">()",
"Ljava9/util/stream/Stream$Builder<",
"TT;>;"
}
.end annotation
.line 1148
new-instance v0, Ljava9/util/stream/Streams$StreamBuilderImpl;
invoke-direct {v0}, Ljava9/util/stream/Streams$StreamBuilderImpl;-><init>()V
return-object v0
.end method
.method public static concat(Ljava9/util/stream/Stream;Ljava9/util/stream/Stream;)Ljava9/util/stream/Stream;
.locals 3
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava9/util/stream/Stream<",
"+TT;>;",
"Ljava9/util/stream/Stream<",
"+TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1387
.local p0, "a":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<+TT;>;"
.local p1, "b":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<+TT;>;"
invoke-static {p0}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 1388
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 1391
new-instance v0, Ljava9/util/stream/Streams$ConcatSpliterator$OfRef;
.line 1392
invoke-interface {p0}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;
move-result-object v1
invoke-interface {p1}, Ljava9/util/stream/Stream;->spliterator()Ljava9/util/Spliterator;
move-result-object v2
invoke-direct {v0, v1, v2}, Ljava9/util/stream/Streams$ConcatSpliterator$OfRef;-><init>(Ljava9/util/Spliterator;Ljava9/util/Spliterator;)V
.line 1393
.local v0, "split":Ljava9/util/Spliterator;, "Ljava9/util/Spliterator<TT;>;"
invoke-interface {p0}, Ljava9/util/stream/Stream;->isParallel()Z
move-result v1
if-nez v1, :cond_1
invoke-interface {p1}, Ljava9/util/stream/Stream;->isParallel()Z
move-result v1
if-eqz v1, :cond_0
goto :goto_0
:cond_0
const/4 v1, 0x0
goto :goto_1
:cond_1
:goto_0
const/4 v1, 0x1
:goto_1
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v1
.line 1394
.local v1, "stream":Ljava9/util/stream/Stream;, "Ljava9/util/stream/Stream<TT;>;"
invoke-static {p0, p1}, Ljava9/util/stream/Streams;->composedClose(Ljava9/util/stream/BaseStream;Ljava9/util/stream/BaseStream;)Ljava/lang/Runnable;
move-result-object v2
invoke-interface {v1, v2}, Ljava9/util/stream/Stream;->onClose(Ljava/lang/Runnable;)Ljava9/util/stream/BaseStream;
move-result-object v2
check-cast v2, Ljava9/util/stream/Stream;
return-object v2
.end method
.method public static empty()Ljava9/util/stream/Stream;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">()",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1158
invoke-static {}, Ljava9/util/Spliterators;->emptySpliterator()Ljava9/util/Spliterator;
move-result-object v0
const/4 v1, 0x0
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v0
return-object v0
.end method
.method public static generate(Ljava9/util/function/Supplier;)Ljava9/util/stream/Stream;
.locals 3
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(",
"Ljava9/util/function/Supplier<",
"+TT;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1345
.local p0, "s":Ljava9/util/function/Supplier;, "Ljava9/util/function/Supplier<+TT;>;"
invoke-static {p0}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 1346
new-instance v0, Ljava9/util/stream/StreamSpliterators$InfiniteSupplyingSpliterator$OfRef;
const-wide v1, 0x7fffffffffffffffL
invoke-direct {v0, v1, v2, p0}, Ljava9/util/stream/StreamSpliterators$InfiniteSupplyingSpliterator$OfRef;-><init>(JLjava9/util/function/Supplier;)V
const/4 v1, 0x0
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v0
return-object v0
.end method
.method public static iterate(Ljava/lang/Object;Ljava9/util/function/Predicate;Ljava9/util/function/UnaryOperator;)Ljava9/util/stream/Stream;
.locals 8
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
"S:TT;>(TS;",
"Ljava9/util/function/Predicate<",
"TS;>;",
"Ljava9/util/function/UnaryOperator<",
"TS;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1287
.local p0, "seed":Ljava/lang/Object;, "TS;"
.local p1, "hasNext":Ljava9/util/function/Predicate;, "Ljava9/util/function/Predicate<TS;>;"
.local p2, "next":Ljava9/util/function/UnaryOperator;, "Ljava9/util/function/UnaryOperator<TS;>;"
invoke-static {p2}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 1288
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 1289
new-instance v7, Ljava9/util/stream/Stream$2;
const-wide v1, 0x7fffffffffffffffL
const/16 v3, 0x410
move-object v0, v7
move-object v4, p2
move-object v5, p0
move-object v6, p1
invoke-direct/range {v0 .. v6}, Ljava9/util/stream/Stream$2;-><init>(JILjava9/util/function/UnaryOperator;Ljava/lang/Object;Ljava9/util/function/Predicate;)V
.line 1331
.local v0, "spliterator":Ljava9/util/Spliterator;, "Ljava9/util/Spliterator<TT;>;"
const/4 v1, 0x0
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v1
return-object v1
.end method
.method public static iterate(Ljava/lang/Object;Ljava9/util/function/UnaryOperator;)Ljava9/util/stream/Stream;
.locals 7
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
"S:TT;>(TS;",
"Ljava9/util/function/UnaryOperator<",
"TS;>;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1224
.local p0, "seed":Ljava/lang/Object;, "TS;"
.local p1, "f":Ljava9/util/function/UnaryOperator;, "Ljava9/util/function/UnaryOperator<TS;>;"
invoke-static {p1}, Ljava9/util/Objects;->requireNonNull(Ljava/lang/Object;)Ljava/lang/Object;
.line 1225
new-instance v6, Ljava9/util/stream/Stream$1;
const-wide v1, 0x7fffffffffffffffL
const/16 v3, 0x410
move-object v0, v6
move-object v4, p1
move-object v5, p0
invoke-direct/range {v0 .. v5}, Ljava9/util/stream/Stream$1;-><init>(JILjava9/util/function/UnaryOperator;Ljava/lang/Object;)V
.line 1244
.local v0, "spliterator":Ljava9/util/Spliterator;, "Ljava9/util/Spliterator<TT;>;"
const/4 v1, 0x0
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v1
return-object v1
.end method
.method public static of(Ljava/lang/Object;)Ljava9/util/stream/Stream;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(TT;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1169
.local p0, "t":Ljava/lang/Object;, "TT;"
new-instance v0, Ljava9/util/stream/Streams$StreamBuilderImpl;
invoke-direct {v0, p0}, Ljava9/util/stream/Streams$StreamBuilderImpl;-><init>(Ljava/lang/Object;)V
const/4 v1, 0x0
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v0
return-object v0
.end method
.method public static varargs of([Ljava/lang/Object;)Ljava9/util/stream/Stream;
.locals 1
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">([TT;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1196
.local p0, "values":[Ljava/lang/Object;, "[TT;"
invoke-static {p0}, Ljava9/util/J8Arrays;->stream([Ljava/lang/Object;)Ljava9/util/stream/Stream;
move-result-object v0
return-object v0
.end method
.method public static ofNullable(Ljava/lang/Object;)Ljava9/util/stream/Stream;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">(TT;)",
"Ljava9/util/stream/Stream<",
"TT;>;"
}
.end annotation
.line 1183
.local p0, "t":Ljava/lang/Object;, "TT;"
if-nez p0, :cond_0
invoke-static {}, Ljava9/util/stream/Stream$-CC;->empty()Ljava9/util/stream/Stream;
move-result-object v0
goto :goto_0
:cond_0
new-instance v0, Ljava9/util/stream/Streams$StreamBuilderImpl;
invoke-direct {v0, p0}, Ljava9/util/stream/Streams$StreamBuilderImpl;-><init>(Ljava/lang/Object;)V
const/4 v1, 0x0
.line 1184
invoke-static {v0, v1}, Ljava9/util/stream/StreamSupport;->stream(Ljava9/util/Spliterator;Z)Ljava9/util/stream/Stream;
move-result-object v0
:goto_0
return-object v0
.end method
JAVA库的反编译方法调用了缺少的方法(Build with crash):
.method public static varargs getLastNotNullValue([Ljava/lang/Object;)Ljava/lang/Object;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">([TT;)TT;"
}
.end annotation
.annotation runtime Ljava/lang/SafeVarargs;
.end annotation
.line 56
.local p0, "values":[Ljava/lang/Object;, "[TT;"
invoke-static {p0}, Ljava9/util/stream/Stream;->of([Ljava/lang/Object;)Ljava9/util/stream/Stream;
move-result-object v0
sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;
invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->filter(Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;
move-result-object v0
invoke-interface {v0}, Ljava9/util/stream/Stream;->findFirst()Ljava9/util/Optional;
move-result-object v0
sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;
invoke-virtual {v0, v1}, Ljava9/util/Optional;->orElseGet(Ljava9/util/function/Supplier;)Ljava/lang/Object;
move-result-object v0
return-object v0
.end method
同样的反编译方法(Build without crash):
.method public static varargs getLastNotNullValue([Ljava/lang/Object;)Ljava/lang/Object;
.locals 2
.annotation system Ldalvik/annotation/Signature;
value = {
"<T:",
"Ljava/lang/Object;",
">([TT;)TT;"
}
.end annotation
.annotation runtime Ljava/lang/SafeVarargs;
.end annotation
.line 56
.local p0, "values":[Ljava/lang/Object;, "[TT;"
invoke-static {p0}, Ljava9/util/stream/Stream$-CC;->of([Ljava/lang/Object;)Ljava9/util/stream/Stream;
move-result-object v0
sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$h24iVvNNOyPAWTyqI3I8dzCunHY;
invoke-interface {v0, v1}, Ljava9/util/stream/Stream;->filter(Ljava9/util/function/Predicate;)Ljava9/util/stream/Stream;
move-result-object v0
invoke-interface {v0}, Ljava9/util/stream/Stream;->findFirst()Ljava9/util/Optional;
move-result-object v0
sget-object v1, Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;->INSTANCE:Lru/m4bank/mpos/service/network/utils/-$$Lambda$EmptyUtils$2lJJnncNhWO5-cW1nB8g96aMo4M;
invoke-virtual {v0, v1}, Ljava9/util/Optional;->orElseGet(Ljava9/util/function/Supplier;)Ljava/lang/Object;
move-result-object v0
return-object v0
.end method
问题:这是 kotlin 错误还是我做错了什么,然后如何使用存储库中的JAVA-库(其中包含带有静态方法的接口(interface))在 android <7 上并且不会崩溃?
最佳答案
您正在尝试在 Android API 级别 < 24 中使用 Java Stream Api,这是不可能的。
根据 Android API 级别检查您可以使用和不能使用的内容 here
关于android - java.lang.NoSuchMethodError in external java dependency inside the java dependency from Kotlin on Android 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58737497/
我正在查看Kotlin Github page我注意到 Kotlin 语言本身大部分是用 Kotlin 编写的:我只是想知道,一种语言怎么可能大部分都是用它自己的语言编写的?在您可以使用正在创建的语言
我有以下非常简单的 kotlin 代码来演示中缀函数 com.lopushen.demo.presentation 包 fun main(args: Array) { print("Hello
我在 Java 中有 2 个模型类,其中一个扩展了另一个 @UseStag public class GenericMessages extends NavigationLocalizationMap
Kotlin 代码 runBlocking { flow { for (i in 0..4) { println("Emit $i")
这三个 Kotlin 插件和它们的实际作用有什么区别? plugins { id 'kotlin-android' id 'org.jetbrains.kotlin.android'
我正在为某些现有库添加 Kotlin 原生 linuxX64 目标支持。库已成功编译,但在运行测试用例时,出现以下运行时错误: kotlin.native.concurrent.InvalidMuta
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 2 年前。 Improve t
我创建了一个类并向其添加了一个与成员函数具有相同签名的扩展,并执行了这个方法,它总是执行成员方法。 class Worker { fun work() = "...working" } fun
我知道传递给函数的参数将被视为“val”,即使变量被初始化为“var”。但这对我来说一直是个问题。在下面的示例代码中,我想通过使用函数“changeNum”修改变量“num”的值。但当然,Kotlin
现在,我正在尝试用 Kotlin 重写我的 Java 应用程序。然后,我遇到了日志语句,比如 log.info("do the print thing for {}", arg); 所以我有两种方法可
有点出名article关于许多语言的异步编程模型的状态,指出它们存在“颜色”问题,特别是将生态系统分为两个独立的世界:异步和非异步。以下是这种语言的属性: 每个函数都有一种颜色,红色或蓝色(例如asy
因为 KDoc 文档生成引擎是 abandoned in favor of Dokka , Kotlin 文档应该称为“KDoc 注释”,还是“Dokka 注释”? 最佳答案 如所述here , KD
我想在可空对象上传递函数引用。以 Android 为例,假设我想使用 Activity#onBackPressed来自作为该事件的子级的片段。 如果我想调用这个函数,我可以很容易地做到 activit
我有一个列表 (x, y)其中y只能是 0 或 1 这样 例如: [(3, 0), (3, 1), (5, 1)] [(5, 0), (3, 1), (5, 1)] [(1, 1), (3, 1),
从强类型语言的定义来看: A strongly-typed programming language is one in which each type of data (such as intege
这不能编译的事实是否意味着它们不是一流的类型? fun foo(s: String): Int = s.length // This won't compile. val bar = foo 有没有办
如果在 Java i++是一个表达式和 i++;是一个表达式语句,分号(;) 在 Kotlin 中是可选的,是 i++ Kotlin 中的表达式或表达式语句? 最佳答案 i++是一个表达式,因为它有一
代码(如下所示)是否正确?它取自 Kotlin-docs.pdf 的第 63 页,这也是 https://kotlinlang.org/docs/reference/generics.html 的最后
我正在尝试使用 Kotlin 为 Android 的一些全局 API 解析器(检查网络连接、调用 API 并通过来自源的单个调用返回格式化数据),并且在某些时候我不得不创建一个通用类型 object就
kotlinlang 中的任务: 使用月份变量重写此模式,使其与格式 13 JUN 1992(两位数字、一个空格、一个月份缩写、一个空格、四位数字)中的日期相匹配。 答案是:val month = "
我是一名优秀的程序员,十分优秀!