> To avoid reflection you could write your 1.4+ specific code in an
> helper/utility class.
[quoted text clipped - 15 lines]
> }
> }
Dangerous thing to do. The point the exception is thrown from is not
always obvious, for frequently executed code it can be slow and it does
not clearly distinguish between 1.2 and 1.4 code. There's a piece on it
in Java Puzzlers.
My preferred approach allows the 1.2 code to be compiled against the 1.2
rt.jar. Make a class of 1.4 specific stuff that implements an 1.2
compatible interface. Compile the 1.4 class with -target 1.4 and use the
static initialiser to check that it really is running on 1.4+. The 1.2
code can be compiled against the 1.2 rt.jar and use Class.forName to
load the 1.4 specific stuff (once).
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Jean-Francois Briere - 26 Jul 2006 20:43 GMT
> Dangerous thing to do.
Not really
> The point the exception is thrown from is not always obvious,
Yes it is for well documented methods .
> for frequently executed code it can be slow
Agreed
> and it does not clearly distinguish between 1.2 and 1.4 code.
Yes it does for well documented methods .
> My preferred approach ...
I like this approach. In fact this is a cleaner (using interfaces and a
version factory approach) and more efficient approach.