Re: [Java] Function Binding Redux (long post)

John Moeller <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
Rene Rivera wrote:
> So on the suggestion from JW (John Welch), I tried an experiment. He 
> suggested a rather devious possible solution; Create an empty stub 
> *.java and corresponding *.class that loads the native class:
> 
> ====java
> package boost;
> 
> public class A
> {
>      static {
>          java.lang.System.out.println("stub/boost/A/static_init...");
>          java.lang.System.loadLibrary("boost_A.dll");
>      }
> }
> ====
> 
> And as part of the loadLibrary() redefine the same class to the 
> native+JNI version (see attached test code). 

Is the part between "====" what you are referring to?  I didn't get any 
attachments with your message.

> Hence when one uses the A 
> class, it can be loaded, but one is freed from having to declare all the 
> redundant Java members. 

This would be cool.  Although, there's something scratching at the back 
of my head about this one.  Something about defining a class twice, or 
not being able to undefine a class, or something else.

> But, and it's a big one, it seems the Java 
> compiler *does not load* a class in order to use it during compilation. 
> Rather it seems to read the .class file directly. Which seems to me a 
> rather serious case of false advertising from Sun.

Blech.  Yeah, that would be the case, wouldn't it?  There must be some 
sensible way to stub a class; there are J2EE developers who do it all 
the time when they use AOP toolkits that use link-time weaving.

>> Unless, that is, you use class C 
>> explicitly, through Reflection.  Which is a gross way to use a class.
> 
> Yes, that's fairly gross. Given your experiments, and mine, this only 
> leaves your suggestion of interfaces or of a launcher that puts in a 
> custom class loader.

Darn.  I was really hoping that you and JW would prove me wrong.  :(

Personally, I'm in favor of the interface approach; I think that despite 
the somewhat awkwardness in object construction, it offers more 
flexibility.  There's always the possibility of offering both 
approaches, though.

I'll get started on some basic glue code; I still need to study up on 
bytecode a little.  I could probably throw something together in Java 
that uses BCEL, though, until we can migrate some of it to native code.

-- 

John Moeller
[email protected]


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.