gpt4 book ai didi

java - 为什么接口(interface)变量默认是静态的和最终的?

转载 作者:bug小助手 更新时间:2023-10-28 10:40:01 25 4
gpt4 key购买 nike

为什么Java中的接口(interface)变量默认是static和final的?

最佳答案

来自 Philip Shaw 的 Java 界面设计常见问题解答:

Interface variables are static because Java interfaces cannot be instantiated in their own right; the value of the variable must be assigned in a static context in which no instance exists. The final modifier ensures the value assigned to the interface variable is a true constant that cannot be re-assigned by program code.

source

关于java - 为什么接口(interface)变量默认是静态的和最终的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2430756/

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