官术网_书友最值得收藏!

Using Kotlin in a new Android project

For new Kotlin projects created in Android Studio 3.x, the main activity will be already defined in Kotlin, so that we can start writing Kotlin code right away:

Adding a new Kotlin file is similar to adding a Java file. Simply right-click on a package and select new | Kotlin File/Class:

The reason why the IDE says Kotlin File/Class and not simply Kotlin class, which is analogous to Java class, is that we can have more members defined inside a single file. We will discuss this in more detail in Chapter 2, Laying a Foundation.

Notice that Kotlin source files can be located inside the java source folder. We can create a new source folder for Kotlin, but it is not required:

Running and debugging a project is exactly the same as in Java and does not require any additional steps besides configuring Kotlin in the project:

Starting from Android Studio 3.0, various Android templates will also allow us to select a language. This is the new Configure Activity wizard:

主站蜘蛛池模板: 兴化市| 广德县| 孟连| 宣恩县| 富平县| 温泉县| 乌审旗| 义乌市| 延寿县| 黄大仙区| 佛学| 临夏市| 阿瓦提县| 施秉县| 沂水县| 高陵县| 石门县| 白城市| 华坪县| 巴东县| 卢龙县| 太康县| 华池县| 南康市| 商南县| 孝感市| 大洼县| 玉林市| 车险| 包头市| 隆安县| 旌德县| 兴山县| 罗平县| 台北市| 平舆县| 疏勒县| 蒙城县| 东莞市| 和静县| 阿巴嘎旗|