@
nekocode 从官方的这段描述看,像是被编(fan)译(yi)为代码了
布局中赋予 id 的元素,被编译为 Activity 类的 extension property
(如果是这样,这思想很像 C#的 partial class ,
而以前开发.NET WinForm/WebForm 的童鞋, 从来没有 findViewById 这种烦恼)
----
```java
// Using R.layout.activity_main from the main source set
import kotlinx.android.synthetic.main.activity_main.*
public class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
textView.setText("Hello, world!") // Instead of findView(R.id.textView) as TextView
}
}
```
textView is an extension property for Activity, and it has the same type as declared in activity_main.xml.