Kotlin有没有任何物业订购协议?

问题描述 投票:1回答:1

对于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

嗯,我知道有人可以随心所欲地写,但我想知道是否有任何约定,根据某些未指定的级别列出属性?

android kotlin conventions coding-style
1个回答
1
投票

来自Kotlin docs(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.

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

© www.soinside.com 2019 - 2024. All rights reserved.