最终关键字如何在Android中运行 [英] How final keyword works in Android

查看:96
本文介绍了最终关键字如何在Android中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在Java中我们将 final 关键字用于变量或其他内容,以使其值不被更改。

I Know that in Java we use final keyword to variables or something else to make its values not to be changed.

使用 final 有什么区别,如下例所示?

What is the difference in using final as in the example below?

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final TextView campoTexto = (TextView) findViewById(R.id.campoTexto);

    Button botaoTexto = (Button) findViewById(R.id.botaoTexto);
    Button botaoCor = (Button) findViewById(R.id.botaoCor);

    final RelativeLayout fundoTela = (RelativeLayout) findViewById(R.id.fundoTela);


推荐答案

这是java ... final 关键词在android中总是相同或者在android中都没有。这取决于你申请的内容。

It is java...final key word is always the same either in android or not in android. It depends on what you apply to.

例如

应用于变量意味着初始化后无法更改。

Apply to the variable means it cannot be changed after initialized.

应用于方法意味着它不能重载方法。

Apply to method means it cannot be overload the method.

申请上课,你不能覆盖该课程。

Apply to the class and you cannot override that class.

这篇关于最终关键字如何在Android中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆