#781 Class methods / "This" type reflection in static context

tactics Wed 14 Oct 2009

I have a mixin with a static method. I want to get the Type object for the class calling the method.

For example, I want to write a method to do this:

mixin Fooable 
{
  static Void printQName() {...} // prints qualified name of calling class
}

class Bar : Fooable
{
  ...
}

class Baz : Fooable
{
  ...
}

// elsewhere...
Bar.printQName // outputs myPod::Bar
Baz.printQName // outputs myPod::Baz

I realize there is some weirdness to this kind of thing (such as calling Fooable.printQName), but it would be pretty nice to achieve this effect somehow. Is there currently any way to do this? Or do I need to resort to passing the type as a parameter to printQName?

brian Wed 14 Oct 2009

Fan is pretty much like Java in that case.

If have to have an instance to call Obj.type. You can either pass it in, or make your method non-static.

tactics Wed 14 Oct 2009

Rats. I can work around it pretty easily, but I just wanted to make sure I wasn't missing anything. All of Fan's reflection tends to go to your head after a while.

Login or Signup to reply.