接口与枚举 [英] Interfaces vs. enums

查看:79
本文介绍了接口与枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在接口和枚举之间,哪个更适合于声明常量?为什么会这样呢?

Between interfaces and enums, which is better for declaring constants? Why is it so?

推荐答案

使用Enums声明常量总是更好,因为接口的目标处于完全不同的层次上。是的,有很多接口具有 public static final 常量,但是我觉得枚举的唯一工作就是为您提供这些常量。

Its always better to use Enums to declare constants as the objective of interfaces are on a totally different level. Yes, there are lots of interfaces which have a public static final constants, but I feel that enums exclusive job is to provide you these constants.

这篇关于接口与枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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