(原)java擴充語言:.Kotlin實踐-基本安裝與使用

來源:互聯網
上載者:User

標籤:

kotlin是一個新生的基於jvm的語言,可以看成java的擴充語言,由JetBrains開發,初次見到他是之前在公司的安卓團隊看到他們使用kotlin開發android,頓時覺得好奇,後來慢慢的研究了這個預言。

為什麼要開發和使用kotlin這門語言,官方的說法是:

Concise  SafeVersatileInteroperable

 並且舉了一個例子:

Get rid of those pesky NullPointerExceptions, you know, The Billion Dollar Mistakevar output : Stringoutput = nullAnd of course, Kotlin protects you from mistakenly operating on nullable types, including those from Javaprintln(output.length())And if you check a type is right, the compiler will auto-cast it for youfun calculateTotal(obj: Any) {  if (obj is Invoice) {    obj.calculateTotal()  }}

看到這裡我大概明白了,然後我想說:滾

 

安裝:

一:在 點擊下載kotlin 下載kotlin的二進位檔案或者在github上拖源碼,都可以,我是使用的源碼編譯,但結果都是產生如下結構:

 

 

二:接下來開始配置環境變數:

export KOTLIN_HOME=XXXXXXX/kotlincexport PATH=${PATH}:${KOTLIN_HOME}/bin

很基本的環境變數,linux的,不多說了。

 

三:寫HelloWorld(hello.kt):

fun main(args: Array<String>) {    println("Hello, World!")}

四:開始編譯和運行:

kotlinc-jvm hello.kt -include-runtime -d hello.jarjava -jar hello.jar

 

 

到這一步,我們已經使用kotlin的文法,寫出了一個helloworld的代碼,並且已經編譯產生一個jar,並且是包含main的可以直接運行,接下來開始分析下這個jar:

 

我們看到它產生的jar,也是包含一個main的java類,java裡面的main方法是可以被final修飾的。

 

(原)java擴充語言:.Kotlin實踐-基本安裝與使用

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.