Kotlin编码规范
来源:互联网 发布:sql同字段求和语句 编辑:程序博客网 时间:2024/04/28 07:47
资料原文:http://www.kotlinlang.org/docs/reference/coding-conventions.html
本文包含了KotLin语言的当前编码格式。
命名格式
默认情况下采用Java编码规范:
- 采用驼峰式命名
- 类型以大写字母开头
- 方法和属性以小写字母开始
- 使用4个空格缩进
- 公有方法应该有类似Kotlin的文本文档
冒号
分开类型和父类的冒号之前有一个空格,在类型和实例分割的冒号钱没有空格
interface Foo<out T : Any> : Bar { fun foo(a: Int): T}
Lambdas表达式
In lambda expressions, spaces should be used around the curly braces, as well as around the arrow which separates the parameters from the body. Whenever possible, a lambda should be passed outside of parenthes
list.filter { it > 10 }.map { element -> element * 2 }
lambdas which are short and not nested, it’s recommended to use the it convention instead of declaring the parameter explicitly. In nested lambdas with parameters, parameters should be always declared explicitly.
Unit
如果一个函数的返回类型为Unit,这个返回类型可以被忽略,该关键字的作用是函数不需要返回:
fun foo() { // ": Unit" is omitted here}
1 0
- Kotlin编码规范
- Kotlin语言编码规范
- Kotlin编码规范
- [kotlin系列] (s1_1) 代码风格、编码规范
- Kotlin学习(4):编码规范
- Kotlin编码规范和基本类型--kotlin官方文档学习
- Kotlin 从学习到 Android 第三章 编码规范
- Kotlin-03.编码规范/代码风格(Coding Conventions)
- Kotlin 学习笔记(二) 编码规范和导入包
- Kotlin 编程规范
- 编码规范
- 规范编码
- 编码规范
- 编码规范
- 编码规范
- 编码规范
- 编码规范
- 编码规范
- 机器学习(五)逻辑回归分类
- ios andorid ui图之间的转换
- java中continue、break、return
- 强连通性(poj1236 poj2186)
- RelativeLayout常用属性介绍
- Kotlin编码规范
- Android 根据时间戳转换成多久之前
- 3.4.7、使用 systemd 管理配置 Docker
- 数字游戏
- 使用idea开发scala
- jsp中与javaBean相关的标签
- HTML head 头标签
- LeetCode(91) Decode Ways
- tomcat 重启,tomcat查看日志