<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### [Kotlin and Android](https://developer.android.com/kotlin/) Kotlin現在是Android上的官方語言。它富有表現力,簡潔而強大。最重要的是,它可與我們現有的Android語言和運行時互操作。 [開始](http://www.hmoore.net/alex_wsc/kotlin/691945) ### 現代。表現力。安全。 Kotlin在表達方面很簡潔。它包含可空性和不變性的安全功能,可以使您的Android應用程序在默認情況下保持健康和高效。 ### 更安全的代碼 編寫更安全的代碼,避免NullPointerExceptions在您的應用程序中。 ~~~ var output: String output = null // Compilation error ================================== val name: String? = null // Nullable type println(name.length()) // Compilation error ~~~ ### 可讀和簡潔 #### 數據類 專注于表達您的想法并編寫更少的樣板代碼 ~~~ button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ doSomething(); } }); ~~~ #### Lambda表達式 使用lambdas簡化代碼。 **Java** ~~~ button.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ doSomething(); } }); ~~~ **Kotlin** ~~~ button.setOnClickListener { doSomething() } ~~~ ### 默認和命名參數 使用默認參數減少重載函數的數量。使用命名參數調用函數以使代碼更具可讀性。 ~~~ fun format(str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true, divideByCamelHumps: Boolean = false, wordSeparator: Char = ' ') { … } ================================== // Call function with named arguments. format(str, normalizeCase = true, upperCaseFirstLetter = true) ~~~ ### 跟你說再見 findViewById 避免findViewById()在代碼中調用。專注于用較少的冗長來編寫邏輯。 ~~~ import kotlinx.android.synthetic.main.content_main.* class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // No need to call findViewById(R.id.textView) as TextView textView.text = "Kotlin for Android rocks!" } } ~~~ ### 無需繼承即可擴展功能 擴展函數和屬性使您可以輕松擴展類的功能而無需繼承它們。調用代碼是可讀且自然的。 ~~~ // Extend ViewGroup class with inflate function fun ViewGroup.inflate(layoutRes: Int): View { return LayoutInflater.from(context).inflate(layoutRes, this, false) } ================================== // Call inflate directly on the ViewGroup instance override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val v = parent.inflate(R.layout.view_item) return ViewHolder(v) } ~~~ ### 100%可與Java互操作 根據需要添加少量或多少Kotlin。Kotlin是一種可與Java完全互操作的JVM語言。 ~~~ // Calling Java code from Kotlin class KotlinClass { fun kotlinDoSomething() { val javaClass = JavaClass() javaClass.javaDoSomething() println(JavaClass().prop) } } ================================== // Calling Kotlin code from Java public class JavaClass { public String getProp() { return "Hello"; } public void javaDoSomething() { new KotlinClass().kotlinDoSomething(); } } ~~~ ### 偉大的工具支持 Android Studio 3.0提供了一些工具來幫助您開始使用Kotlin。將Java代碼粘貼到Kotlin文件中時,轉換整個Java文件或動態轉換代碼片段。 ![](https://box.kancloud.cn/61d1cbf7a7c5b3ebda88df0a6eec08df_460x106.png) ### Kotlin是開放的 就像Android一樣,Kotlin是Apache 2.0下的一個開源項目。我們選擇Kotlin重申了我們在開發和發展Android平臺時對開放式開發人員生態系統的承諾,我們很高興看到語言不斷發展。 [在Github上看kotlin](https://github.com/JetBrains/kotlin) ### 使用Kotlin構建的應用程序 許多應用程序已經使用Kotlin構建 - 從最熱門的初創公司到財富500強公司。 ### 最新消息和資源 ![](https://box.kancloud.cn/f48fc749f6d80e0cb9edd3e9c24c1b9e_416x563.jpg) ![](https://box.kancloud.cn/5b88164536420a1568f90ea8bd820d8d_418x575.jpg)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看