Kotlin call java method with Class argument

前端 未结 4 693
忘了有多久
忘了有多久 2021-02-04 01:39

I want to use Spring RestTemplate in Kotlin like this:

//import org.springframework.web.client.RestTemplate
fun findAllUsers(): List {
          


        
4条回答
  •  迷失自我
    2021-02-04 02:25

    First, you will make a new class - UserList.kt (the name is our owner)

    Inside:

    class UserList : MutableList by ArrayList()
    

    After that, you can call your method that has a RestTemplate

    val response: List < Item > ? = restTemplate.getObject("yourEndpoint", UserList::class.java)
    

    It may be returns null, so you need to take care of that.

提交回复
热议问题