Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the different between Kotlin File/Class and Kotlin Script

i programming kotlin language to 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 File in kotlin

like image 379
Youn Tivoli Avatar asked Jan 08 '19 00:01

Youn Tivoli


1 Answers

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.

like image 146
hotkey Avatar answered Sep 27 '22 18:09

hotkey