现代编程语言
使开发人员更快乐.
永远开源的Github

Get started Try online

Good for

Latest from Kotlin

Kotlin Early Access Preview

试用最新的Kotlin功能,然后再发布

Learn more

Try Kotlin

最简单的版本
面向对象的Hello
Coroutines
More examples
                    fun main() {
                        println("Hello World")
                    }
                

Why Kotlin?

  • Concise

    大大减少样板代码的数量

    /*
     Create a POJO with getters, setters, `equals()`, `hashCode()`, `toString()` and `copy()` in a single line:
    */
    
    data class Customer(val name: String, val email: String, val company: String)
    
    // Or filter a list using a lambda expression:
    
    val positiveNumbers = list.filter { it > 0 }
    
    // Want a singleton? Create an object:
    
    object ThisIsASingleton {
        val companyName: String = "JetBrains"
    }
    
  • Safe

    避免整个类的错误,例如空指针异常

    /*
     Get rid of those pesky NullPointerExceptions, you know, The Billion Dollar Mistake
    */
    
    var output: String
    output = null   // Compilation error
    
    // Kotlin protects you from mistakenly operating on nullable types
    
    val name: String? = null    // Nullable type
    println(name.length())      // Compilation error
    
    // And if you check a type is right, the compiler will auto-cast it for you
    
    fun calculateTotal(obj: Any) {
        if (obj is Invoice)
            obj.calculateTotal()
    }
    
  • Interoperable

    利用JVM,Android和浏览器的现有库

    /*
     Use any existing library on the JVM, as there’s 100% compatibility, including SAM support.
    */
    
    import io.reactivex.Flowable
    import io.reactivex.schedulers.Schedulers
    
    Flowable
        .fromCallable {
            Thread.sleep(1000) //  imitate expensive computation
            "Done"
        }
        .subscribeOn(Schedulers.io())
        .observeOn(Schedulers.single())
        .subscribe(::println, Throwable::printStackTrace)
    
    // Target either the JVM or JavaScript. Write code in Kotlin and decide where you want to deploy to
    
    import kotlin.browser.window
    
    fun onLoad() {
        window.document.body!!.innerHTML += "<br/>Hello, Kotlin!"
    }
    
  • Tool-friendly

    选择任何Java IDE或从命令行构建

Kotlin Usage Highlights

Start Using Kotlin Today!

在您的应用中构建您的第一个Kotlin应用
最喜欢的IDE

Get started
esc

by  ICOPY.SITE