What is painfully tricky to do with reflection is the "implements
ApplicationListener" part. Instantiating a class compiled normally
that implements the interface is easy, but it requires a stub for
ApplicationListener in order to compile on non-Macintosh platforms.
Doing it without the stub requires heroics above and beyond the
call of duty.
I seem to recall a posting on this list announcing code that did so
using a dynamic proxy, avoiding the need to redistribute Apple's
stubs. It might have been MRJ Adapter. However, having to
distribute a 3rd party library isn't much different from having to
distribute Apple's stubs.
I think it depends on whether or not you end up trying to compile or
runtime load something that isn't there.
MacOSXIconButton here would be something I wouldn't want to try to
compile or probably even load on Windows, by creating the interface
instance with reflection inside a
if (MacOSX) {
it won't do either.
The Windows alternative
up1 = new IconButton(new File("C:\\"));
would also implement ButtonInterface so subsequent references would
be as a ButtonInterface and no problems.
I seem to remember someone claiming sometime that you didn't actually
need the reflection. You could include a source reference to say the
MacOSXIconButton in such a way that the compiler or classloader
wouldn't try to resolve them. Maybe it was that the class existed and
could load. As long as you didn't hit any actual platform specific
native methods you were still all right.
That probably would not work for non-existent Apple classes. But if
they were only referenced in a class accessed on another platform
with reflection as first shown above I don't think you'd have a
problem. Any changes to them that actually needed them to be compiled
would have to be on OS X. You might not use them in the most natural
manner that you could if you didn't have any cross-platform concerns
but I think it'd be shy of painful.
There might be something different or specific to the Apple stub code
that I'm not thinking of. I think where I've used those it has
actually tended to be OS X platform specific code from the get go.
Possibly the problem is that 'build all' type situations are involved
where everything is re-compiled every time whether changed or not?
Then yes again reflection buys you nothing when you try to compile
something that won't resolve dependencies without failing. Although
would that fail the whole build process?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden