# Kotlin 注释 > 原文: [https://www.programiz.com/kotlin-programming/comments](https://www.programiz.com/kotlin-programming/comments) #### 在本文中,您将了解 Kotlin 注释,以及为什么以及如何使用它们。 在编程中,注释是程序的一部分,旨在供您和您的其他程序员理解代码。 Kotlin 编译器(Kompiler)完全忽略了它们。 与 Java 类似,在 Kotlin 中有两种类型的注释 * `/* ... */` * `// ....` * * * ## 传统注释`/* ... */` 这是一条多行注释,可以跨越多行。 Kotlin 编译器会忽略从`/*`到`*/`的所有内容。 例如, ```kt /* This is a multi-line comment. * The problem prints "Hello, World!" to the standard output. */ fun main(args: Array) { println("Hello, World!") } ``` 传统注释也用于记录 Kotlin 代码(KDoc)并稍有变化。 KDoc 注释以`/**`开头并以`*/`结束。 * * * ## 行尾注释`//` 编译器忽略从`//`到行尾的所有内容。 例如, ```kt // Kotlin Hello World Program fun main(args: Array) { println("Hello, World!") // outputs Hello, World! on the screen } ``` 上面的程序包含两个行尾注释: ```kt // Kotlin Hello World Program ``` 和 ```kt // outputs Hello, World! on the screen ``` * * * ## 以正确的方式使用注释
注释不能代替解释英文书写不好的代码的方法。 编写结构良好且易读的代码,然后使用注释。 一些人认为代码应该是自我记录的,注释应该很少。 但是,我必须完全不同意(这是我个人的观点)。 使用注释来解释复杂的算法,[正则表达式](http://www.rexegg.com/)或在其中您选择一种技术而非其他技术(以供将来参考)的场景中并没有什么问题。 在大多数情况下,请使用注释来解释“为什么”而不是“如何”,这样您就很好了。