2 Replies Latest reply: Jul 15, 2010 2:43 AM by 843798 RSS

    Access protected static method using reflection

    843798
      When I tried to invoke a protected static method using reflections, it gave me a "IllegalAccessException".
      How can I do the same???


      try
                {
                     Class1 cgcache = new Class1();
                     Class ob = cgcache.getClass();
                     Class[] args1 = new Class[1];
                     args1[0] = ClassName1.class;
                     Method strMethod = ob.getDeclaredMethod("gtDAct", args1);
                     Object arglist[] = new Object[1];
                     assertEquals(objName, strMethod.invoke(null,arglist));
                }
                catch(NoSuchMethodException ne)
                {
                     ne.printStackTrace();
                }