本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

Kotlin ドキュメント
Kotlin
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts
ディスカッション

Kotlin ガイド · 6/6

Key Concepts

この章は現在、英語でのみ提供しています。

The last chapter covers four ideas that make Kotlin feel like Kotlin: null safety, extension functions, lambdas, and coroutines.

Null safety

A String can never hold null; to allow it, write String?. Members of a nullable value cannot be called directly, which turns most NullPointerExceptions into compile errors.

fun main() {
    var nickname: String? = null      // nullable thanks to ?
    // println(nickname.length)       // compile error

    println(nickname?.length)         // null: safe call
    println(nickname?.length ?: 0)    // 0: Elvis operator supplies a default
    nickname = "Kotlin"
    println(nickname!!.length)        // 6: throws if null

    nickname?.let { println("Nickname is $it") }   // runs only when not null
}
OperatorMeaning
?.call if not null, otherwise the result is null
?:use the right side when the left is null
!!assert not null, throw otherwise
as?safe cast that returns null on failure

Use !! sparingly. After a null check or an is check, the compiler treats the variable as the narrower type: a smart cast.

fun lengthOf(value: Any?): Int {
    if (value == null) return 0
    if (value is String) return value.length   // smart cast to String
    if (value is List<*>) return value.size
    return value.toString().length
}

fun findUser(id: Int): String? = if (id == 1) "admin" else null

fun requireUser(id: Int): String =
    findUser(id) ?: throw IllegalArgumentException("Unknown user: $id")

Smart casts fail when the value might change after the check, as with a mutable var property. Copy it into a local val first.

Extension functions

Extensions add functions to a class without editing or subclassing it. Put the receiver type before the name; inside, the receiver is this.

fun String.initials(): String =
    split(" ").filter { it.isNotBlank() }.joinToString("") { it.first().uppercase() }

val <T> List<T>.secondOrNull: T?
    get() = if (size >= 2) this[1] else null

fun main() {
    println("kotlin is fun".initials())     // KIF
    println(listOf(1, 2, 3).secondOrNull)   // 2
}

Extensions do not modify the class. They compile to static functions taking the receiver as the first argument, are resolved from the static type at compile time, and cannot see private members. Much of the standard library, including filter, and , is built this way.

この章について質問がありますか?
前の章Errors and Testing
map
let

Lambdas and higher-order functions

A higher-order function takes functions as parameters or returns one. Function types look like (Int) -> Int, lambdas are written in braces, and a lambda with one parameter can refer to it as it.

fun applyTwice(x: Int, f: (Int) -> Int): Int = f(f(x))

fun isEven(n: Int) = n % 2 == 0

fun main() {
    val double: (Int) -> Int = { it * 2 }
    val add = { a: Int, b: Int -> a + b }

    println(applyTwice(3, double))          // 12
    println(applyTwice(3) { it + 10 })      // 23: trailing lambda
    println(add(2, 5))                      // 7
    println((1..6).filter(::isEven))        // [2, 4, 6]: function reference

    val words = listOf("apple", "kiwi", "banana", "fig")
    val result = words
        .filter { it.length > 3 }
        .sortedBy { it.length }
        .map { it.uppercase() }
    println(result)                         // [KIWI, APPLE, BANANA]
}

When the last parameter is a function, the lambda can move outside the parentheses, which is why repeat(3) { ... } or Gradle's dependencies { ... } look like built-in syntax. An inline function is copied into each call site, avoiding lambda allocations.

Coroutine basics

Coroutines are lightweight tasks that suspend without blocking a thread. The language provides the suspend keyword; launch, async and friends come from the kotlinx-coroutines-core library.

import kotlinx.coroutines.*

suspend fun fetchPrice(item: String): Int {
    delay(300)              // waits without blocking the thread
    return item.length * 1000
}

fun main() = runBlocking {
    val job = launch {
        delay(100)
        println("launch: work with no result")
    }

    val apple = async { fetchPrice("apple") }
    val melon = async { fetchPrice("melon") }
    println("Total: ${apple.await() + melon.await()}")   // both run concurrently

    job.join()
}

A suspend function can only be called from a coroutine or another suspend function. launch returns a Job for work without a result; async returns a Deferred whose value you read with await(). runBlocking bridges regular and coroutine code and belongs only in main or tests.

Under structured concurrency, children run inside a parent scope that waits for them all, and a failure cancels the siblings. Move blocking I/O onto a suitable thread pool with withContext(Dispatchers.IO).

suspend fun readConfig(path: String): String = withContext(Dispatchers.IO) {
    java.io.File(path).readText()
}

suspend fun loadAll(paths: List<String>): List<String> = coroutineScope {
    paths.map { async { readConfig(it) } }.awaitAll()
}

Summary

  • T and T? are different types; handle null with ?., ?: and smart casts, and keep !! rare.
  • Extension functions add behavior without changing a class and are resolved at compile time.
  • Lambdas, higher-order functions and trailing-lambda syntax underpin the standard library and Kotlin DSLs.
  • Coroutines use suspend, launch and async to make asynchronous code read sequentially.

Further reading in the official docs:

  • Kotlin documentation
  • Null safety
  • Extensions
  • Higher-order functions and lambdas
  • Coroutines guide
  • Kotlin Koans exercises

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。