Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di Kotlin
Kotlin
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
Discussioni

Guida a Kotlin · 2/6

Syntax Basics

Per ora questo capitolo è disponibile solo in inglese.

This chapter covers the syntax you will use every day: variables, functions, conditionals, loops, and string templates. With these in hand you can already write useful small programs.

Variables: val and var

val declares a read-only variable that cannot be reassigned; var declares one that can. Idiomatic Kotlin reaches for val first and uses var only when a value really has to change. Types are usually inferred, so you can leave them out.

const val MAX_USERS = 100    // compile-time constant, top level or inside an object

fun main() {
    val language = "Kotlin"  // inferred as String
    var count: Int = 0       // or spell out the type
    count += 1
    // language = "Java"     // error: val cannot be reassigned
    println("$language $count / $MAX_USERS")
}

Note that val fixes the reference, not the object. With val list = mutableListOf(1), calling list.add(2) is perfectly legal.

Functions

Functions start with fun; parameter and return types follow a colon. When the body is a single expression, replace the braces with = and let the compiler infer the return type.

fun add(a: Int, b: Int): Int {
    return a + b
}

fun square(x: Int) = x * x   // expression body, returns Int

fun greet(name: String, greeting: String = "Hello", mark: Char = '!'): String =
    "$greeting, $name$mark"

fun main() {
    println(add(2, 3))                      // 5
    println(square(4))                      // 16
    println(greet("Sam"))                   // Hello, Sam!
    println(greet("Ana", greeting = "Hi"))  // Hi, Ana!
    println(greet(mark = '?', name = "Lee")) // Hello, Lee?
}

Parameters with default values can be skipped, and named arguments let you pass only what you need in any order. That removes most of the overload boilerplate common in Java. A function that returns nothing useful has the return type Unit, which you normally omit.

if and when are expressions

if produces a value, which is why Kotlin has no ternary operator: you assign the result of if directly.

fun describe(score: Int): String {
    val passed = if (score >= 60) "pass" else "fail"

    val grade = when {
        score >= 90 -> "A"
        score >= 80 -> "B"
        score >= 70 -> "C"
        else -> "F"
    }
    return "$passed ($grade)"
}

fun kind(x: Any): String = when (x) {
    0, 1 -> "zero or one"
    in 2..9 -> "a single digit"
    is String -> "a string of length ${x.length}"
    else -> "something else"
}

when replaces Java's switch. Given a subject, branches can match values, ranges (in) or types (is). Without a subject it behaves like an if-else chain, testing conditions top to bottom. Used as an expression it must cover every case, so you usually need an branch. Being able to call inside the branch is a smart cast, explained in chapter 6.

Domande su questo capitolo?
Capitolo precedenteGetting StartedCapitolo successivoTypes and Data
else
x.length
is String

String templates

Embed values with $name or arbitrary expressions with ${...}. Raw strings use triple quotes, and trimIndent() strips the common leading indentation.

fun main() {
    val user = "Ana"
    val items = listOf("apple", "pear")
    println("$user has ${items.size} items in the cart")
    println("Total: ${items.size * 3} dollars")

    val json = """
        {
          "name": "$user",
          "count": ${items.size}
        }
    """.trimIndent()
    println(json)
}

Ranges and loops

There is no C-style for (i = 0; i < n; i++). Instead, for ... in iterates over ranges and collections.

ExpressionMeaningValues
1..5closed range1, 2, 3, 4, 5
0..<5end excluded, same as 0 until 50, 1, 2, 3, 4
10 downTo 0 step 3counting down by 310, 7, 4, 1
'a'..'e'character rangea, b, c, d, e
fun main() {
    for (i in 1..5) print("$i ")
    println()
    for (i in 10 downTo 0 step 3) print("$i ")
    println()

    val fruits = listOf("apple", "pear", "grape")
    for ((index, fruit) in fruits.withIndex()) {
        println("$index: $fruit")
    }

    var n = 3
    while (n > 0) {
        println("$n left")
        n--
    }

    repeat(2) { println("round $it") }

    outer@ for (x in 1..3) {
        for (y in 1..3) {
            if (x * y == 4) break@outer   // leaves both loops
            println("$x x $y")
        }
    }
}

Ranges also work in membership checks such as if (age in 20..29). To break out of an outer loop, label it (outer@) and use break@outer.

Summary

  • Prefer val; use var only for values that must change.
  • Functions support default and named arguments, and single-expression bodies use =.
  • if and when are expressions; when can match values, ranges and types.
  • Build strings with $name and ${expression} templates.
  • Loop with for ... in over ranges like 1..5, 0..<n, downTo and step, or over collections.

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.