Tag: retrofit2 kotlin reflect

使用reflection读取Kotlin函数注释值?

给定一个像这样的接口方法(Android Retrofit),如何在运行时从Kotlin代码读取注解参数中指定的URL路径? ApiDefinition接口: @GET(“/api/somepath/objects/”) fun getObjects(…) 阅读注释值: val method = ApiDefinition::getObjects.javaMethod val verb = method!!.annotations[0].annotationClass.simpleName ?: “” // verb contains “GET” as expected // But how to get the path specified in the annotation? val path = method!!.annotations[0].???????? 更新1 感谢您的回答。 我还在苦苦挣扎,因为我看不到要使用什么types来执行以下操作: val apiMethod = ApiDefinition::getObjects ….然后将该函数引用传递到这样的方法(它被重用) private fun getHttpPathFromAnnotation(method: Method?) : String { val a […]