[Pharo-users] Java "this" against our "thisContext"

Camille Teruel camille.teruel at gmail.com
Tue Mar 25 07:07:08 EDT 2014

On 25 mars 2014, at 11:42, Sergi Reyner <sergi.reyner at gmail.com> wrote:

> 2014-03-25 10:30 GMT+00:00 Benjamin <benjamin.vanryseghem.pharo at gmail.com>:
> Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called. You can refer to any member of the current object from within an instance method or a constructor by using this.
> from: http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
> thisContext in smalltalk points to the execution context of the method being currently evaluated.
> So definitely this and self are the “same” (as long as we do not talk about inner classes)
> Yeah, that part I truly understand.I do know enough Java and Smalltalk to understand that "this" and "self" are equivalent (topic which somehow evaporated from the debate, and replaced with "this is the same and thisContext because [unintelligible Java code]".
> thisContext does not exist in Java AFAIK
> That´s exactly what my intuition led me to. But when I tried to explain that I, too, don´t think that Java has a concept of "thisContext" I was presented with this:
> Field a = sun.misc.VM.class.getDeclaredField("directMemory");
> a.setAccessible(true);
> a.get(null);
> Which, after some investigation, and as far as I understood, looks to me as if all it does is retrieve what "this" points to.

For me, that snippet just returns the value of a static field named directMemory in the class sun.misc.VM.
Field a = sun.misc.VM.class.getDeclaredField("directMemory"); // reify the field
a.setAccessible(true); // by-pass visibility checks (maybe it's private)
a.get(null); // get the value of that field

So that's just an example of simple introspection, but it's not related to stack introspection.

> It´s not really relevant because what I was arguing is that Smalltalk reflection operates at a higher level, which that piece of code proves pretty nicely, but since we got there I´d like to understand everything argued.
> Cheers,
> Sergi
> PS: Note that I´m not trying to win an internet debate, but simply to understand :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20140325/e04065cc/attachment.html>

More information about the Pharo-users mailing list