Getting info on a class without instantiating it..

Although, counter-intuitively (to me, at least), function despatch is also resolved at compile-time.

I.e. the selection of which method to invoke based on signature etc is performed at compile-time. This is why when you provide two methods with signatures that differ only in that some of the args are subtypes of some of the others, the JVM does NOT choose which one to invoke based upon the types of the arguments in the invocation; it was determined at compile-time. This is a major bummer when trying to make libraries which are automatically polymorphic (i.e. anyone can choose to specialise any of the classes which generate objects your lib passes to arguments, and your library will seamlessly adopt the newly specialised class).

IMHO, Java is generally a poor tool for writing API’s :(.

[quote]I have the strongest suspicion here that Adam can solve this problem with protected singleton instances and normal inheritance, using that custom classloader idea.
[/quote]
In the spirit of the forum ;), how? Sorry to be thick here, but I’m getting stuck trying to work out how it will work without requiring copy-n-paste code into each loaded class.

PS I chose Newless Cluebies because I really find Classloader stuff hard-going (despite having used them quite a bit), and count myself pretty rubbish at making complex Classloader’s :(. I usually stumble over traps in the JLS (basically subtle things I’d not noticed before, or had forgotten since the last time I was working with loaders :)).

[quote]I.e. the selection of which method to invoke based on signature etc is performed at compile-time. This is why when you provide two methods with signatures that differ only in that some of the args are subtypes of some of the others, the JVM does NOT choose which one to invoke based upon the types of the arguments in the invocation; it was determined at compile-time.
[/quote]
There’s no alternative in this situation. As an overloaded (not overridden) method has a different method signature, it can throw different exceptions and return different values. And allowing the runtime to invoke based on the arguments’ runtime types in some circumstances but not others would cause too much chaos to be worthwhile.

This is definitely an area where some extension to the language would make a lot of sense - being able to “extend” a method so as to provide different arguments but leave the rest of the signature alone would be an interesting possibility. The only workaround I’ve seen that makes much sense is to turn each method into a sort of “callback”, where the object of the specific type is asked to call a specific method on the calling object, using a correctly-typed reference. It ain’t cute, but it works. :-/

[quote]In the spirit of the forum ;), how? Sorry to be thick here, but I’m getting stuck trying to work out how it will work without requiring copy-n-paste code into each loaded class.
[/quote]
No need for any copy-n-paste. As I said, you can use one of the bytecode manipulators to append your boiler-plate code to the class after you’ve read it from disk but before letting the VM know about it.