Kotlin是否有任何财产订购约定?

时间:2019-03-27 01:49:36

标签: android kotlin conventions coding-style

对于Kotlin中的任何类,我通常都有许多不同的属性。我想知道是否根据这些属性的类型对它们进行了任何转换。我使用的基本类型是

  • var fields
  • private var fields
  • lateinit var fields
  • private lateinit var fields
  • val fields上的所有内容
  • lazy fields
  • private lazy fields

很好的通用分类将具有在同一组中声明的相同类型的属性。然后,我要做的是先声明公共字段,然后声明私有字段。我想知道怎么样,lazylateinit首先是什么。还是var之后会怎样? private varlateinit varlazy val

我知道有人可以随便写什么,但是我想知道是否有任何约定可以根据未指定的特定级别列出属性?

1 个答案:

答案 0 :(得分:1)

从Kotlin文档(https://kotlinlang.org/docs/reference/coding-conventions.html):

Do not sort the method declarations alphabetically or by visibility, and do not separate regular methods from extension methods. Instead, put related stuff together, so that someone reading the class from top to bottom would be able to follow the logic of what's happening. Choose an order (either higher-level stuff first, or vice versa) and stick to it.

我认为该规则也可以应用于属性。

相关问题