title: Java object is not an instance of declaring class
body: <pre><code>public class SendEmailImpl 
  {     
      private boolean isValidEmailAddress(String email)
      {
          boolean stricterFilter = true;
          String stricterFilterString = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
          String laxString = ".+@.+\\.[A-Za-z]{2}[A-Za-z]*";
          String emailRegex = stricterFilter ? stricterFilterString : laxString;
          Pattern p = Pattern.compile(emailRegex);
          Matcher m = p.matcher(email);
          return m.matches();
      } 
  }
  </code></pre>
  
  <p>I tried to call this code using reflection</p>
  
  <pre><code>@Test
  public void testValidEmail() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
  {
      Method method = SendEmailImpl.class.getDeclaredMethod("isValidEmailAddress", String.class);
      method.setAccessible(true);
      Boolean invoke = (Boolean) method.invoke("isValidEmailAddress", String.class);
  
      assertTrue(invoke);
      System.out.println("Testing E-mail validator - case example@example.com");
  }
  </code></pre>
  
  <p>But I get error</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: object is not an instance of declaring class</p>
  </blockquote>
  
  <p>Do you have any idea where is my code wrong?</p>
  
  <p>I also tried this:</p>
  
  <pre><code>@Test
  public void testValidEmail() throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
  {
      Method method1 = SendEmailImpl.class.getDeclaredMethod("isValidEmailAddress", String.class);
      method1.setAccessible(true);
  
      Boolean invoke = (Boolean)method1.invoke(String.class);
      assertTrue(invoke);
      System.out.println("Testing E-mail validator - case example@example.com");
  }
  </code></pre>
  
  <p>But the result is the same.</p>