From: Samuele P. <ped...@bl...> - 2004-04-27 15:37:15
|
At 08:27 26.04.2004 -0400, Chermside, Michael wrote: >I am trying to write some jython code for printing out descriptions of >java objects (using reflection). One of the tasks I need to perform >is, given a java.lang.reflect.Method object, to obtain a description >of it's modifiers (public final static, etc). > >Fortunately, there's a handy function for doing this: > java.lang.reflect.Modifier.toString(int) > >It takes an int (primitive), and returns a String. The int can be >obtained from java.lang.reflect.Method.getModifiers(), but for this >example I'll simply use 2 (which is the code for "private"). Here's >a sample jython program: > > Jython 2.1 on java1.3.1_11 (JIT: null) > Type "copyright", "credits" or "license" for more information. > >>> import java.lang.reflect.Modifier as Modifier > >>> Modifier.toString(2) # should return 'private' > '2' > >>> > >I expected it to return 'private' but it returned '2' instead. I've >got two questions: > > (1) Why? it's glitch in how java method are dispatched, in disambiguating the unbound method from the static one. What you are getting is the behavior of java.lang.Object.toString We can do better in most cases, and there's a bug in the tracker to remind about this, can't say right now whether things will improve for 2.2 or after. > (2) How do I fix it? other people have showed workarounds |