I would like to use the java.text.Normalizer class from Java 1.6 to do Unicode normalization, but my code has to be able to run on Java 1.5.
I don't mind if the code running on 1.5 doesn't do normalization, but I don't want it to give NoClassDefFoundError
s or ClassNotFoundException
s when it runs.
What's the best way to achieve this?
The usual way of doing this is via reflection, i.e. don't refer directly to the class in question, but invoke it programmatically. This allows you to catch exceptions gracefully if the code in question doesn't exist, and either ignore it, or try something else. Reflection throws ClassNotFoundException
, which is a nice normal exception, rather than NoClassDefFoundError
, which is a bit scarier.
In the case of java.text.Normalizer
, this should be pretty easy, since it's just a couple of static methods, and easy to invoke via reflection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With