This only works because all Strings are compile time constants. If you have Strings that are computed at runtime or read from external resources, it breaks.
Although this doesn't have anything to do with your question, I'd like to point out that you must be VERY carful when comparing Objects, such as Strings. In the code above, I don't think
if (type=="C7")
does what you think. This compares if type is the same String object as the literal "C7". It does NOT compare the contents of the type with the string literal. To compare the contents you should do this:
code:
if ("C7".equals(type))
In fact, when you compare objects, you should usually use the equals() method.
Sorry if I'm breaking the purpose of this particular thread. However, this paradigm shows up often enough that I wanted to help you avoid making the same mistake in the future.