本文介绍了如何在一行中声明多个属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个具有多个 lateinit
一种类型属性的类.我认为像这样在单独的行上声明它们太冗长了:
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:
lateinit var a: String
lateinit var b: String
所以我想像这样在一行中声明它们:
so I would like to declare them on one line like this:
lateinit var b, c: String // error: Property getter or setter expected
但我收到一个错误Property getter or setter expected
.有没有办法在 Kotlin 的一行中声明多个属性?
But I get an error Property getter or setter expected
. Is there any way to declare several properties on one line in Kotlin?
推荐答案
不,没有办法做到这一点.许多 Java 风格指南都不赞成在同一行上声明多个属性,因此我们没有在 Kotlin 中实现对此的支持.
No, there is no way to do that. Declaring multiple properties on the same line is frowned upon by many Java style guides, so we did not implement support for that in Kotlin.
这篇关于如何在一行中声明多个属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!