How to declare several properties on one line

前端 未结 3 1206
情深已故
情深已故 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:21

    Looking at the grammar this is not possible:

    property (used by memberDeclaration, declaration, toplevelObject)
      : modifiers ("val" | "var")
          typeParameters? (type "." | annotations)?
          (multipleVariableDeclarations | variableDeclarationEntry)
          typeConstraints
          ("by" | "=" expression SEMI?)?
          (getter? setter? | setter? getter?) SEMI?
      ;
    

    You can only do destructing declarations with:

    val (name, age) = person
    

提交回复
热议问题