Nitesh Sawant wrote:Java 7 has new feature : "switch statement with java.lang.String".
What may be the reason for not adding feature as "switch statement with java.lang.Object" ?
Henry Wong wrote:Also, let's not forget that Java requires that the targets for the case statements must be compile time constants.
Henry Wong wrote:And Java already have it well defined for strings. To switch on anything else, a new concept of object literals will have to be created.
Mike Simmons wrote:It wouldn't really be difficult to make rules for an Object switch statement that was equivalent to a series of if/else statements.
If they wanted to.
But there also wouldn't be much point, since such an addition wouldn't really be any better than a series of if/else statements.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Mike Simmons wrote:
Henry Wong wrote:Also, let's not forget that Java requires that the targets for the case statements must be compile time constants.
Or enums.
Henry Wong wrote:And Java already have it well defined for strings. To switch on anything else, a new concept of object literals will have to be created.
Or they could just change the rules, as they did when they added enums.
Winston Gutkowski wrote:
But there also wouldn't be much point, since such an addition wouldn't really be any better than a series of if/else statements.
Again, probably a personal preference, but I really like the "look" of switch statements. To me they're visually very clean.
Henry Wong wrote:... I don't expect the 1000th case statement ...
Henry Wong wrote:Although, enums are not compile time constants -- as defined by the specification. The possible values of the enum are constants, and can be determined at compile time -- so I guess it is possible to use this same technique to switch on the wrapper objects as well.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|