dir.by  
  Поиск  
Компьютер, программы
Kotlin
 The Kotlin console app works like Android Jetpack Compose 
посмотрели 689 раз
обновлено: 22 June 2026
Download an example:
Step 1. Creating a new console application
Step 2. Add the code to the Main.kt file
• my setContent function sets the content on the screen and calls the lambda function myFunc1 to do so
• my Surface function draws borders on the screen and draws its content inside and calls the lambda function myFunc2 to do this
• my Text function just displays the text on the screen

We could call it like this: setContent({ -> some kind of code })
But here is the right way: setContent{ some kind of code }     More what is Kotlin Lamda Function ...
 
  Kotlin     File Main.kt
fun main() {

     setContent {
          Surface(
               color = "green"
          )
          {
               Text("Hello!")
               Text("I want coffee :)")
               Text("Thank you")
          }
     }
}

fun setContent(myFunc1:() -> Unit)
{
     myFunc1();
}

fun Surface(color:String, myFunc2:() -> Unit)
{
     println("┌---------------------------------")
     println("|")
     println("|")

     myFunc2();

     println("|")
     println("|")
     println("└---------------------------------")
}

fun Text(description:String)
{
     println("| $description ");
}
Step 3. Running the program
 
Let's see the result:
На заметку!
 
← Previous topic
Generic, template class in Kotlin | Example: class MyBook<T> { ... }
 
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

  Объявления  
  Объявления  
 
What is Kotlin?
Why is IntelliJ IDEA the most popular development environment for Kotlin?
Download and install IntelliJ IDEA to explore Kotlin
Create a new console project to explore Kotlin | IntelliJ IDEA
Setting the value
Declare the variable and set the value in Kotlin | val, var, lateinit, constant: const val, global variable: companion object
null
null value, use the symbol ? and ?. and !! and ?: and !!. and ?. in Kotlin
Int, Float, Boolean, Char ...
Integer numbers in Kotlin are: Byte, UByte, Short, UShort, Int, UInt, Long, ULong
Decimal numbers in Kotlin are: Float, Double
A flag with values of true or false in Kotlin is: Boolean
The symbol in Kotlin is: Char
Convert number to text in Kotlin | Int → String
String
The string, the text in Kotlin is: String
Interpolate strings in Kotlin. Example: val address:String = "${street}, ${country}"
What is the difference between String and StringBuilder ?
Enum
What is an enumeration (enum) in Kotlin ?
How do I find enum by value in Kotlin ?
Function
fun() { ... } is a function in Kotlin. The function is needed to perform an action.
Lambda function
Lambda function in Kotlin. Example 1: var myFunc1 : (a:Int, b:Int) -> Int = { p1, p2 -> p1 + p2 };
Collections and Arrays
Create collections list, set, map and an array array in Kotlin
Class
What is class in Kotlin? Example: class MyBook { ... } | Primary and secondary constructor | block init
lateinit is a late initialization for the class field | Kotlin
class that inherits from interface in Kotlin | Example: class MyBook : IBook { ...}
Unnamed class that inherits from interface in Kotlin | Example: val book1 = object : IBook { ...}
Generic, template class in Kotlin | Example: class MyBook<T> { ... }
Writing a program
The Kotlin console app works like Android Jetpack Compose

  Ваши вопросы присылайте по почте: info@dir.by  
Яндекс.Метрика