title: Java reflection calling a method from same context
body: <p>I have spend the last 1 or 2 hours diving into Java reflection.
  I think i'm starting to have a proper understanding. </p>
  
  <p>I could not however find a few answers I was looking for.</p>
  
  <p>What I came to understand is that reflection suffers a big(biggest?) performance hit from class lookups.</p>
  
  <p>I have 2 questions.</p>
  
  <p>How can you call a method from within the current context(is it even possible?)?
  And will the performance hit from class lookups be canceled out when calling within the current context?</p>
  
  <p>for example:</p>
  
  <pre><code>class User {
     private String name;
  
     public getName(){ return name; }
     public setName(String name){ this.name = name; }
  
     public void doSomething() {
         //some random stuff
         //I would like this method to invoke randomMethod();
         //Since it is within the same context(this)
         //Will this reduce the performance cost?
  
         //Please assume from my goals that I will ALWAYS know the name of the method i                  want to call.
        //So I wont need to loop through all available methods.
  
     }
  
     public void randomMethod() {
  
     }
  }
  </code></pre>
  
  <p>Im trying to achieve some kind of dispatcher.
  For example for web development in Java.</p>
  
  <p>Im not interested in frameworks etc.</p>
  
  <p>So if a user enters an url <a href="http://www.hiurl.com/home/index" rel="nofollow">http://www.hiurl.com/home/index</a></p>
  
  <p>Where home is the controller and index the action(the method name to be called by reflection).</p>
  
  <p>If you have good arguments why to absolutely avoid this apart from the many chances of failing, please let me know aswell.</p>
  
  <p>I hope my question is clear.
  Thanks for taking the time to read and I look forward to read your replies. </p>