I discovering the programming language kotlin for some weeks, and I always start with new File/Class, and I've noticed lately to kotlin Script in the menu and I ask now what's different between the Script and the normal File in kotlin
In a Kotlin source *.kt
file, you can place top-level declarations, such as types and top-level functions and properties, but not code statements that are not nested into some declarations.
A Kotlin Script *.kts
file, on contrary, contains code statements on the top level without any nesting. These statements are an equivalent of a main
function. It is allowed to contain types, too, but with some limitations similar to those placed on nested type declarations.
*.kts
file is the actual body of the main function. –
Diaphragm There are some differences a Kotlin File (.kt) is used for developing structured applications. Contains classes, functions, and other constructs. It’s compiled and run as part of an application. while Kotlin Script (.kts) is mainly used for quick scripts and automation tasks. Kotlin Script allows writing code directly without the need for classes or functions. It's interpreted and executed immediately.
© 2022 - 2024 — McMap. All rights reserved.