【发布时间】:2018-06-24 04:39:49
【问题描述】:
我正在学习 spring boot 并且是 kotlin 的新手。 此Java函数转换为kotlin代码时会报错。 如何重写这个kotlin函数?
https://spring.io/guides/gs/consuming-rest/
@Bean
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
Quote quote = restTemplate.getForObject(
"http://gturnquist-quoters.cfapps.io/api/random", Quote.class);
log.info(quote.toString());
};
}
通过idea将这些代码转换为kotlin后:
@Bean
@Throws(Exception::class)
fun run(restTemplate: RestTemplate): CommandLineRunner {
return { args ->
val quote = restTemplate.getForObject(
"http://gturnquist-quoters.cfapps.io/api/random", Quote::class.java)
log.info(quote.toString())
}
}
请告诉我如何更正此代码。
【问题讨论】:
-
SAM 转换未正确使用:stackoverflow.com/a/48265190/8073652
标签: java spring-boot kotlin