小编har*_*min的帖子

如何在Retrofit中为挂起功能创建呼叫适配器?

我需要创建一个可处理此类网络呼叫的改造呼叫适配器:

@GET("user")
suspend fun getUser(): MyResponseWrapper<User>
Run Code Online (Sandbox Code Playgroud)

I want it to work with Kotlin Coroutines without using Deferred. I have already have a successful implementation using Deferred, which can handle methods such as:

@GET("user")
fun getUser(): Deferred<MyResponseWrapper<User>>
Run Code Online (Sandbox Code Playgroud)

But I want the ability make the function a suspending function and remove the Deferred wrapper.

With suspending functions, Retrofit works as if there is a Call wrapper around the return type, so suspend fun getUser(): User is treated as fun getUser(): …

java android kotlin retrofit kotlin-coroutines

14
推荐指数
3
解决办法
1715
查看次数

由于Android上的lint classpath错误,Gradle构建失败

我有一个Android应用程序,运行以下命令时其构建失败: ./gradlew clean build -Pbuild=dev --stacktrace

这是我收到的错误:

> Task :app:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':app:lint'.
> No value has been specified for property 'lintClassPath'.
Run Code Online (Sandbox Code Playgroud)

应用模块的build.gradle文件:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

apply plugin: 'io.fabric'

apply plugin: "androidx.navigation.safeargs"

// For Epoxy
kapt {
    correctErrorTypes = true
}

android {
    kotlinOptions {
        jvmTarget = '1.6'
    }
    compileSdkVersion 28
    defaultConfig { …
Run Code Online (Sandbox Code Playgroud)

android lint gradle kotlin android-gradle-plugin-3.3.0

11
推荐指数
3
解决办法
2589
查看次数

How to check if a class has overriden a default method from an interface using Reflection in Kotlin or Java?

I have an interface with a default method, and two classes which implement this interface. One of the classes overrides the default method, and the other does not.

interface MyType {
  fun giveHello(): String = "Hello!"
}

class Polite: MyType {
  // Does not override giveHello()
}

class Rude: MyType {
  override fun giveHello(): String = "I don't like you"
}
Run Code Online (Sandbox Code Playgroud)

我可以giveHello使用反射来访问该方法,如下所示:

val methodOfPolite = Polite::class.java.getDeclaredMethod("giveHello")
val methodOfRude = Rude::class.java.getDeclaredMethod("giveHello")
Run Code Online (Sandbox Code Playgroud)

这里有一件事很奇怪。有礼貌的类不会覆盖giveHello方法,但declaringClass此方法对象的仍指向Polite

因此,有没有一种方法可以检查该类是否确实覆盖了默认接口方法? …

java reflection kotlin

4
推荐指数
1
解决办法
81
查看次数