gpt4 book ai didi

java - 在android中实现关键字

转载 作者:行者123 更新时间:2023-11-29 08:14:17 25 4
gpt4 key购买 nike

在 Android 中我看到这样的代码:

public class Now extends Activity implements View.OnClickListener

这在java中合法吗? View.OnClickListener 在这里到底代表什么。

最佳答案

问题似乎与View.x 的使用有关。正如@Vicente_Plata 在评论中很好地指出的那样:

OnClickListener is an interface declared inside the View class. Like an "inner class" but, rather, an "inner interface


旧答案:
View.OnclickListener 是一个 接口(interface)。它定义了您的 Activity 必须实现的方法,在本例中为 OnClickListener()。任何检查的人都想知道您的类中是否有这样的函数,因此他们可以将 Now 用作 OnclickListener

接口(interface)不提供实现。

此外,来自 this page

Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

关于java - 在android中实现关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5769036/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com