我需要创建一个可处理此类网络呼叫的改造呼叫适配器:
@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(): …
我有一个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)
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) 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。
因此,有没有一种方法可以检查该类是否确实覆盖了默认接口方法? …
kotlin ×3
android ×2
java ×2
android-gradle-plugin-3.3.0 ×1
gradle ×1
lint ×1
reflection ×1
retrofit ×1