jan said:
[...] but tell me how to write a Java
interpreter without reflection, if you can.
Byte code generation[*].
[...]
([*] In fact that's how reflective invocation of methods, and access to
fields, is implemented in the recent Sun JDKs)
No way! Really? Can you give me some reference to back this up?
Back what up ?
The claim that one can use byte-code generation to invoke methods and access
fields is -- I would have thought -- obvious. Note that I'm not claiming that
byecode generation would allow you to discover /what/ members were present;
that would be best handled by reflection. Although, in the situation you
mention, where you have complete control of the invocation environment,
reflection isn't /necessary/. You could still write an interpreter that "knew"
what members existed in the (fixed set of) classes loaded by the primordial
classloader -- say by scanning the JAR(s) -- and which thereafter was in
control of class loading so it also had full information about any other
classes that were loaded dynamically from other places.
Or were you asking for a reference to support the claim that Sun use byte-code
generation in order to invoke methods reflectively ? If so then I refer you to
the source (the full source, not the stuff in src.zip, although the source to
java.lang.reflect.Method does provide some hints). Take a look at the stuff in
the sun.reflect package; the main entry-point is sun.reflect.ReflectionFactory,
and the implementation of sun.reflect.MethodAccessorGenerator is as good a
place to start browsing as any.
-- chris