From: Paul P. <bay...@gm...> - 2011-05-25 14:55:51
|
I'm going to go off on a tangent here, not really directed at this conversation, but somewhat relevant. My opinion is that reflection is a necessary evil that should be avoided whenever possible. One of the key words in that is "necessary." A great use of reflection is for web services or other generated code. And that equivalent is appropriately used in XMLVM. I believe it is okay in this type of situation because all parts using reflection are generated & not typed by hand. E.g. a web service is generated & a client is generated, so if an update occurs, we just regenerate. The "evil" part, in my opinion, comes when developers are manually typing method names & class names into Strings, thus avoiding the compiler. This is unfortunately not a rarity in the real world, such as in configuration files. My hope is that as annotations gain muster, they will help squash that practice where they can. I realize there are exceptions to what I just said, but I still try to avoid it at all costs. Since reflection is learned at a more advanced stage, it seems it is sometimes considered advantageous & advanced to use it, but I believe that to be a misconception. Anyways, I am not trying to contradict anything in this email chain, but rather just get on my soapbox about "evil" reflection & have a conversation in general. I'm interested if anyone has some other thoughts on this. Paul On Fri, May 20, 2011 at 2:10 AM, Panayotis Katsaloulis < pan...@pa...> wrote: > > On May 20, 2011, at 9:56 AM, Arno Puder wrote: > > > hmm. Do you want to be able to call arbitrary *methods* or a certain > method on arbitrary *objects*? For the former you need reflected, for > the latter not. Actually, take a look at [DispatcherObject run] (in > NSObject.m) to get an idea how you can invoke a Java method from C code. > > > > certain method, arbitrary objects. > I did, I actually found these two parts: > java_lang_reflect_Method* method = (*(JAVA_OBJECT (*)(JAVA_OBJECT, > JAVA_OBJECT, JAVA_OBJECT)) targetClass->tib->vtable[ > XMLVM_VTABLE_IDX_java_lang_Class_getMethod___java_lang_String_java_lang_Class_1ARRAY])(targetClass, > methodName, paramTypes); > and > (*(JAVA_OBJECT (*)(JAVA_OBJECT, JAVA_OBJECT, JAVA_OBJECT)) method->tib-> > vtable[ > XMLVM_VTABLE_IDX_java_lang_reflect_Method_invoke___java_lang_Object_java_lang_Object_1ARRAY])(method, > target, params); > but I am a bit confused how to decode it. > Moreover it seems that they use reflection - that's why I asked. > > > And a last probably silly question: > > How do I convert an ObjC String to java_lang_String ? > > (and for completeness and back?) > > > NSString* toNSString(JAVA_OBJECT o) > JAVA_OBJECT toJavaString(NSString* str) > > both defined in NSString.m > > > Oh , I missed that part - I was looking under java_lang_String :) > > > > ------------------------------------------------------------------------------ > What Every C/C++ and Fortran developer Should Know! > Read this article and learn how Intel has extended the reach of its > next-generation tools to help Windows* and Linux* C/C++ and Fortran > developers boost performance applications - including clusters. > http://p.sf.net/sfu/intel-dev2devmay > _______________________________________________ > xmlvm-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmlvm-users > > |