@Override
  public org.jamon.AbstractTemplateImpl constructImpl(Class<? extends org.jamon.AbstractTemplateImpl> p_class){
    try
    {
      return p_class
        .getConstructor(new Class [] { org.jamon.TemplateManager.class, ImplData.class })
        .newInstance(new Object [] { getTemplateManager(), getImplData()});
    }
    catch (RuntimeException e)
    {
      throw e;
    }
    catch (Exception e)
    {
      throw new RuntimeException(e);
    }
  }
这个方法是怎么回事?每句话都做了些什么事情呢?

解决方案 »

  1.   

    @Override                             //覆盖或实现接口或父类方法的标识
      public org.jamon.AbstractTemplateImpl constructImpl(Class<? extends org.jamon.AbstractTemplateImpl> p_class){           //参数为org.jamon.AbstractTemplateImpl类的子类的类型,并返回父类对象类型
      try
      {
      return p_class
      .getConstructor(new Class [] { org.jamon.TemplateManager.class, ImplData.class })      
      .newInstance(new Object [] { getTemplateManager(), getImplData()});    //调用参数的getConstructor()方法,参数设定为分别new这两个类的对象,然后调用该方法返回的对象的newInstance方法,参数分别为调用括号里两个方法的返回的对象  }
      catch (RuntimeException e)
      {
      throw e;
      }
      catch (Exception e)
      {
      throw new RuntimeException(e);          //异常处理块
      }
      }
      

  2.   

    return p_class
      .getConstructor(new Class [] { org.jamon.TemplateManager.class, ImplData.class })
      .newInstance(new Object [] { getTemplateManager(), getImplData()});主要是通过反射机制返回对象