How to declare several properties on one line

前端 未结 3 1205
情深已故
情深已故 2020-12-09 01:24

I\'m developing a class with several lateinit properties of one type. I think it\'s too verbose to declare each of them on separate line like this:



        
3条回答
  •  心在旅途
    2020-12-09 02:22

    You can use kotlin's destructuring declaration, but it doesn't work for lateinit prefix.

    var (a, b, c, d) = listOf("fly", 23, "slow", 28)
    println("$a $b $c $d")
    

    It is a workaround and creates unnecessary list initialization but it gets the job done.

    Also you won't be able to define variable types yourself but the type inference is automatically done when using destructuring declarations.

提交回复
热议问题