代表匿名内部类的Android Studio [英] Android Studio representing anonymous inner class
问题描述
我使用为我创建的LoginActivity.java在Android Studio 0.3.6中创建了一个全新的Android应用程序.当我查看onCreate
函数时,我看到以下代码:
I created a brand new Android application in Android Studio 0.3.6 with a LoginActivity.java that was created for me. When I view the onCreate
function I see the following code:
但是,当我单击突出显示的(view)-> {
代码时,Android Studio会显示我期望看到的内容:
But when I click on the highlighted (view)-> {
code Android Studio displays what I would have expected to see:
findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
attemptLogin();
}
});
我的问题
- 这叫什么?
- 为什么Android Studio会这样做?
- 这是我可以利用的东西吗,因为它的打字量要少得多?
推荐答案
它正在进行类似于 Java 8 lambda表达式的代码折叠(请参见
It's doing code folding similar to Java 8 lambda expressions (see the docs) even if your code isn't actually compiled with Java 8; it's just a convenience for a more compact display.
如果您想自己使用它们,则可以将 Android Studio 与 Java 1.7 用作编译语言,但是您需要使用v19或以下版本的构建工具更高版本,并且如果您使用某些语言功能,则该功能只能在装有Kit Kat或更高版本的手机上运行.但是, Lambda函数不会给您带来麻烦.
If you want to use them yourself, you can use Android Studio with Java 1.7 as a compile language, but you'll need to be using build tools v19 or later, and if you use certain language features, it will only run on phones with Kit Kat or later. Lambda functions won't get you into trouble, though.
这篇关于代表匿名内部类的Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!