gpt4 book ai didi

java - Kotlin找不到符号Function1构建错误

转载 作者:行者123 更新时间:2023-12-02 13:31:42 27 4
gpt4 key购买 nike

以下是我为了让使用Glide变得更轻松而构建的以下测试方法。

    suspend fun retrieveImage(
glideRequests: GlideRequests,
uri: String,
options: (GlideRequest<Drawable>.() -> Unit)? = null,
targetCallback: ((FutureTarget<Drawable>) -> Unit)? = null
): Drawable? {
// The GlideRequest we should use to run our request
val request = glideRequests.load(uri)

// Apply the options to be used for our request
options?.invoke(request)

// Callback for our Future object so that it can be cancelled if necessary
val drawableFuture = request.submit()
targetCallback?.invoke(drawableFuture)

return try {
withContext(Dispatchers.IO) {
try {
drawableFuture.get()
} catch (unknownHostException: UnknownHostException) {
// Return null, this method was run with no network
null
} catch (interruptionException: InterruptedException) {
// Request has been cancelled
null
}
}
} catch (cancellationException: CancellationException) {
// Coroutine has been cancelled
null
}
}

它构建为JVM的以下组件
import android.graphics.drawable.Drawable;
import com.bumptech.glide.request.FutureTarget;
import io.vadgroup.cirqle.application.GlideRequest;
import io.vadgroup.cirqle.application.GlideRequests;
import kotlinx.coroutines.Dispatchers;
import java.net.UnknownHostException;

@kotlin.Metadata(mv = {1, 1, 16}, bv = {1, 0, 3}, k = 1, d1 = {"\u00000\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u00c6\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002\u00a2\u0006\u0002\u0010\u0002J^\u0010\u0003\u001a\u0004\u0018\u00010\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\u001b\b\u0002\u0010\t\u001a\u0015\u0012\u0004\u0012\u00020\u0006\u0012\u0004\u0012\u00020\u000b\u0018\u00010\n\u00a2\u0006\u0002\b\f2\u001c\b\u0002\u0010\r\u001a\u0016\u0012\n\u0012\b\u0012\u0004\u0012\u00020\u00040\u000e\u0012\u0004\u0012\u00020\u000b\u0018\u00010\nH\u0086@\u00f8\u0001\u0000\u00a2\u0006\u0002\u0010\u000f\u0082\u0002\u0004\n\u0002\b\u0019\u00a8\u0006\u0010"}, d2 = {"Lio/vadgroup/cirqle/utilities/GlideUtil;", "", "()V", "retrieveImage", "Landroid/graphics/drawable/Drawable;", "glideRequests", "error/NonExistentClass", "uri", "", "options", "Lkotlin/Function1;", "", "Lkotlin/ExtensionFunctionType;", "targetCallback", "Lcom/bumptech/glide/request/FutureTarget;", "(Lerror/NonExistentClass;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;", "app_debug"})
public final class GlideUtil {
public static final io.vadgroup.cirqle.utilities.GlideUtil INSTANCE = null;

@org.jetbrains.annotations.Nullable()
public final java.lang.Object retrieveImage(@org.jetbrains.annotations.NotNull()
GlideRequests glideRequests, @org.jetbrains.annotations.NotNull()
java.lang.String uri, @org.jetbrains.annotations.Nullable()
Function1<GlideRequest<android.graphics.drawable.Drawable>, kotlin.Unit> options, @org.jetbrains.annotations.Nullable()
kotlin.jvm.functions.Function1<? super com.bumptech.glide.request.FutureTarget<android.graphics.drawable.Drawable>, kotlin.Unit> targetCallback, @org.jetbrains.annotations.NotNull()
kotlin.coroutines.Continuation<? super android.graphics.drawable.Drawable> p4) {
return null;
}

private GlideUtil() {
super();
}
}

如果您查看上面的Java代码,则可以看到两个不同的Function1对象,一个具有完整的Kotlin路径,而一个没有完整的Kotlin路径。

我怀疑这是由于与Arrow-Core库发生冲突而发生的,因为它们也具有Function1对象。我完全删除了该库,清理了缓存并进行了构建,但是,我仍然遇到这个问题。

我目前使用过Kotlin版本1.3.70和1.3.71

最佳答案

我将以下项目添加到了导入列表的顶部
import kotlin.jvm.functions.*
尽管显示为灰色且似乎未使用,但我能够正确构建该项目。

关于java - Kotlin找不到符号Function1构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60983201/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com