- Android Development with Kotlin
- Marcin Moskala Igor Wojda
- 177字
- 2021-07-02 18:48:32
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:

推薦閱讀
- C#高級編程(第10版) C# 6 & .NET Core 1.0 (.NET開發經典名著)
- Instant Testing with CasperJS
- Instant Zepto.js
- Rake Task Management Essentials
- 數據結構(Python語言描述)(第2版)
- 從0到1:HTML+CSS快速上手
- 手把手教你學C語言
- 實戰Java高并發程序設計(第3版)
- Java程序設計:原理與范例
- 低代碼平臺開發實踐:基于React
- NoSQL數據庫原理
- Go語言編程
- Windows Phone 8 Game Development
- 一步一步跟我學Scratch3.0案例
- Unity 5.X從入門到精通