Color.red和Color.RED之间的差异 [英] Difference between Color.red and Color.RED

查看:242
本文介绍了Color.red和Color.RED之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

setXxx(Color.red) setXxx(Color.RED)的定义之间的真正区别是什么?

What's the real difference between definitions for setXxx(Color.red) and setXxx(Color.RED)?

我在网上找到了以下说明。是关于命名约定吗?

I've found the following explanation on the web. Is it all about naming conventions?


Java最初定义了一些小写的颜色常量名称,违反了大写使用常量的命名规则。它们可用于所有版本的Java:Color.black,Color.darkGray,Color.gray,Color.lightGray,Color.white,Color.magenta,Color.red,Color.pink,Color.orange,Color.yellow,Color .green,Color.cyan,Color.blue

Java originally defined a few color constant names in lowercase, which violated the naming rule of using uppercase for constants. They are available in all versions of Java: Color.black, Color.darkGray, Color.gray, Color.lightGray, Color.white, Color.magenta, Color.red, Color.pink, Color.orange, Color.yellow, Color.green, Color.cyan, Color.blue

Java 1.4为常量添加了正确的大写名称:Color.BLACK,Color.DARK_GRAY,Color.GRAY,Color.LIGHT_GRAY ,Color.WHITE,Color.MAGENTA,Color.RED,Color.PINK,Color.ORANGE,Color.YELLOW,Color.GREEN,Color.CYAN,Color.BLUE

Java 1.4 added the proper uppercase names for constants: Color.BLACK, Color.DARK_GRAY, Color.GRAY, Color.LIGHT_GRAY, Color.WHITE, Color.MAGENTA, Color.RED, Color.PINK, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.CYAN, Color.BLUE


推荐答案

有代码本身:

public final static Color red = new Color(255, 0, 0);

public final static Color RED = red;

大写字母在JDK 1.4中引入(以符合其命名约定, strong>必须以大写字母表示)。

The upper case letters were introduced in JDK 1.4 (to conform to its naming convention, stating that constants must be in upper-case).

实质上,没有区别(除了信封)。

In essence, there are no difference at all (except letter casing).

如果我真的勇敢,Oracle可能会疯狂并删除较低的常量,但那将打破所有其他的代码前面的JDK 1.4。你永远不知道,我建议坚持大写字母的常数。它首先必须被弃用(如Andrew Thompson所述)。

If I want to really be brave, Oracle might go wild and remove constants that is lower-cased, but then that would break all other code that's written pre-JDK 1.4. You never know, I would suggest sticking to uppercase letters for constants. It first has to be deprecated though (as mentioned by Andrew Thompson).

这篇关于Color.red和Color.RED之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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