Hey guys,
I'm curious, why does the Color class have two variable for each color. For example, for color white, WHITE and white. Why does it have both if the do they same job?
-Mel
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Hey guys,
I'm curious, why does the Color class have two variable for each color. For example, for color white, WHITE and white. Why does it have both if the do they same job?
-Mel
I suspect it has something to do with the Java naming conventions. Prior to Java 1.4, the there were only camel case static color fields (white, black, etc.). However, beginning in 1.4 they added the all-caps versions, probably to indicate that these are to be treated as constants.
This is just speculation, though. I didn't find any hard evidence why the upper case versions were added.
I see. Sounds like it very well is the reason. Though if it is, why do the lower case variables still exist?
My guess would be that Sun/Oracle would be rather careful before breaking existing code that uses the lowercase variables.why do the lower case variables still exist?
I'd agree with helloworld's hypothesis. And if this is the case they probably still exist for backwards compatibility - all legacy code that relies on the lower case would break if they were removed, and in many cases updating legacy code is a nightmare and not worth the effort.