繁体   English   中英

Kotlin TypeToken“未解决的参考”错误

[英]Kotlin TypeToken “Unresolved reference” error

我在第5,6和7行收到错误“未解决的回复参考”。你能帮助我理解这个问题吗?

 public class GenericCall {
        public fun genecicCall(functionToBeCalled:String, responseType:String, requestType:String, vararg args:String){
            var request = Class.forName(requestType).newInstance()
            var response = Class.forName(responseType).newInstance()
            var finalType = object : TypeToken<GenericResponse<Class<response>>>(){}.getType()
            var creditresponse: GenericResponse<response>? = AjaxHelper.ajax(Constants.Ajax.ENDPOINT_CREDIT, Constants.Ajax.REQUEST_POST, request, finalType, null)
            return ResponseProcessing.processResponse(creditresponse as Any) as response?
        }
        }
    }

泛型类型参数不能是表达式,它应该是另一种类型,例如类,可能还有其他泛型类型参数。 因此,如果Foo是静态(由编译器推断)类型的response则应该编写例如Class<Foo>而不是Class<response> (第5行)。 在你的情况下,你可能对response一无所知,除了它是Any的一个实例。 因此,您可以使用Class<Any>Class<*> ,无论您喜欢哪个。 GenericResponse类似(第6行)。

由于相同的原因(第7行),表达式也不能出现在as运算符的右侧:此运算符将左侧转换为右侧指定的类型 此外,您的函数似乎没有返回任何内容,因此从中返回有用的值将不起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM