3/29/2024 0 Comments Scratch codesIt's available for Linux, macOS, and Windows. The ki shell ( Kotlin Interactive Shell) is a command-line utility for running Kotlin code in the terminal. Click Share code to embed your sample into any web page or into a Medium article. You can also embed code snippets from the Playground into other websites and even make them runnable. Use the Playground to share your code with others – click Copy link and send it to anyone you want to show the code to. Multiple backends to run the code in: JVM, JS (legacy or IR compiler, or Canvas), or JUnit.įor JS backends, you can also see the generated JS code. Multiple Kotlin versions, including available previews of future versions. The Playground provides ways to customize the execution environment: It automatically imports declarations from the standard library and routines. The Playground highlights the code and shows code completion options as you type. To pass program arguments upon execution, write them in the Program arguments field. Write the executable part in the body of the main() function.Īs in typical Kotlin projects, the main() function in the Playground can have the args parameter or no parameters at all. In the Playground's editor area, you can write code just as you would in a source file:Īdd your own classes, functions, and top-level declarations in an arbitrary order. Kotlin Playground is an online application for writing, running, and sharing Kotlin code in your browser. You can later use the results in the same file by reffering to their auto-generated res* names (they are shown in the corresponding lines). The code lines will run sequentially, providing the results of each call. To evaluate each particular expression in a scratch or a worksheet, run it with Use REPL selected. To rebuild the module automatically before each run of a scratch or a worksheet, select Make module before Run. So, if you modify a module's source files, the changes will propagate to scratches and worksheets when you rebuild the module. Then write your code and run it with the appropriate module selected in the Use classpath of module list.īoth scratches and worksheets use the compiled versions of connected modules. To use classes or functions from a project in a scratch, import them into the scratch file with the import statement, as usual. Worksheets automatically have access to classes and functions from the module where they reside. You can use classes or functions from a Kotlin project in your scratches and worksheets. To get execution results as soon as you stop typing, switch on Interactive mode. The IDE can run code from scratches and worksheets automatically. The execution results will appear in the lines opposite your code. Once you have finished writing your code in a scratch or a worksheet, click Run. There's no need to declare the main() function – all the code you write is executed as if it were in the body of main(). Syntax highlighting, auto-completion, and other IntelliJ IDEA code editing features are supported in scratches and worksheets. To create a Kotlin worksheet in a project directory, right-click the directory in the project tree and select New | Kotlin Class/File | Kotlin Worksheet. Worksheets are useful for writing pieces of code that don't actually make a software unit but should still be stored together in a project, such as educational or demo materials. Worksheets are project files: they are stored in project directories and tied to the project modules. To create a Kotlin scratch, click File | New | Scratch File and select the Kotlin type. Scratches are not tied to projects you can access and run all your scratches from any IntelliJ IDEA window on your OS. Scratch files (or just scratches) let you create code drafts in the same IDE window as your project and run them on the fly. IntelliJ IDEA and Android Studio support Kotlin scratch files and worksheets. Check out these three handy ways to run Kotlin code instantly in different environments: However, if you want to quickly see how a function works or find an expression's value, there's no need to create a new project and build it. Kotlin code is typically organized into projects with which you work in an IDE, a text editor, or another tool.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |