title: Is it possible to see via which child class was a parent's static method called in Java?
body: <p>A little background first. I am looking into the possibility of implementing Ruby's ActiveRecord in Java as cleanly and succinctly as possible. To do this I would need to allow for the following type of method call:</p>
  
  <pre><code>Person person = Person.find("name", "Mike");
  </code></pre>
  
  <p>Which would resolve to something like:</p>
  
  <pre><code>ActiveRecord.find(Person.class, "name", "Mike");
  </code></pre>
  
  <p>The plan is to have Person extend ActiveRecord, which would have a static find method with two parameters (column, value). This method would need to know it was called via Person.find and not another domain class like Car.find and call the find(Class, String, Object) method to perform the actual operation.</p>
  
  <p>The problem I am running into is the finding out via which child class of ActiveRecord the static find method (two param) was called. The following is a simple test case:</p>
  
  <pre><code>public class A {
    public static void testMethod() {
      // need to know whether A.testMethod(), B.testMethod(), or C.testMethod() was called
    }
  }
  
  public class B extends A { }
  public class C extends A { }
  
  public class Runner {
    public static void main(String[] args) {
      A.testMethod();
      B.testMethod();
      C.testMethod();
    }
  }
  </code></pre>
  
  <p>Solutions found so far are load-time or compile time weaving using aspectJ. This would involve placing a call interceptor on the testMethod() in A and finding out what signature was used to call it. I am all for load time weaving but the set up of setting this up (via VM args) is a bit complex. </p>
  
  <p>Is there a simpler solution? </p>
  
  <p>Is this at all possible in java or would need to be done in something like groovy/ruby/python?</p>
  
  <p>Would the approach of using something like ActiveRecord.find for static loads and Person.save for instances be better overall?</p>