Recently i came across static import feature available in java . But was not so happy as this is available only for 1.5 or above. We work on jdk 1.3 and constantly implement interface just for the ease of accessing the constants. But i feel this is a wrong way of utilizing inheritence. Is there any alternative for this? other than of course specifying the class/ interface name . Or is it possible to make use of static import in jdk 1.3 with some tweak??Please note that we use jdk 1.3, eclipse 3.6 and windows xp for our project developement.
Staying on such an old version of the JDK (it's been dead for almost 5 years now, and that's after the 4 year EOL period!) comes with a price -- you can't use the newer features in newer JVMs. You might be able to hack something together using preprocessing, or some special build process - but don't. Bite the bullet and upgrade.
use interface for that purpose is not wrong. it's not a blasphemy on a heavenly concept. make do with what you have, don't get religious.
actually i don't think "static import" is used a lot. it's creepy. i would rather prefix names with originating class names. omitting package names - that I can handle. ommiting class names - very confusing.
Not a solution but it's better to use a final class with public static final variables for constants rather than an interface. Just my two cents.
I believe that using interfaces to group public constants is actually cleaner and easier to read than using static imports. In any case, I would not call it a 'wrong way of utilizing inheritance'.
And yes, there are situations where you simply cannot upgrade to the latest JDK available. This happens often with embedded systems.
other than of course specifying the class/ interface name
What's so horrible about that anyway? It's the correct way of doing it. Much better than static imports, if you choose the names of the classes and the constants well (no need to use interfaces, put the constants where they conceptually belong).