Kelvin Chung wrote:

I'm trying to find a good way of associating an Objective-C object with an arbitrary Java object, so that you could essentially delegate the Objective-C method call to a Java object. I envision that this would have to be done using JNI. However, I don't know the specifics of how it can be done.

How much do you know about JNI? If it's not much, then that's your first task: learn JNI. There are jobject references, method ids, threading invocation requirements, and so on, and you will end up having to know about all of them.

If you don't have a copy of the JNI Specification and Programmer's Guide, you will definitely need that. It doesn't matter what other books you have, the spec is the definitive reference.

  http://java.sun.com/docs/books/jni/

Once you have some experience with JNI, the key thing you need to know is that you must make a global-ref for every jobject that needs to survive between calls to the JVM. You might think of the global- ref as the equivalent of retain, although that's not a precise analogy, and like many analogies, taking it too literally leads to grief. It's closer to a strong reference in GC'ed Obj-C, but that's not an exact analogy either.

I wish you luck on this. Although what you ask for may seem simple or straightforward, it is a considerable undertaking, and I don't think you realize how considerable it is.

And yes, I saw your post entitled "Developing with Cocoa" on java-dev (and the replies), and I think there's a lot more complexity there than what you perceive. In particular, re your reply here:

  http://lists.apple.com/archives/java-dev/2009/May/msg00004.html
  "It seems that using a Cocoa frontend is easier."

Some things seem simple because they are. Other things seem simple only because we're ignorant of how complex they really are. All that happens is you trade one bucket of hurt for a different and frequently larger bucket of hurt. In my opinion, this is one of the latter.

If you prove me wrong, however, please post a follow-up to the list, because I have a use for such a thing, if it works reliably and smoothly.

  -- GG

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to