[JBoss-dev] calling a super method implementation

Scott M Stark scott.stark at jboss.com
Wed Jul 26 18:41:13 EDT 2006


That seems a bit whacked. There is no way to do this via reflection that
I know of. The only way you will be able to do it is to wrap the object
in a proxy and generate a method that uses the invokespecial bytecode op
to call the super class method. This is what is generated when a method
invokes super.method. The superTestDisplay() method in this version of A
just calls super.testDisplay():


public class lang.reflect.A extends lang.reflect.SuperA{
public lang.reflect.A();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method lang/reflect/SuperA."<init>":()V
   4:   return

public void testDisplay();
  Code:
   0:   getstatic       #2; //Field
java/lang/System.out:Ljava/io/PrintStream;
   3:   ldc     #3; //String A.testDisplay()
   5:   invokevirtual   #4; //Method
java/io/PrintStream.println:(Ljava/lang/Str
ing;)V
   8:   return

public void superTestDisplay();
  Code:
   0:   aload_0
   1:   invokespecial   #5; //Method lang/reflect/SuperA.testDisplay:()V
   4:   return

}

-----Original Message-----
From: jboss-development-bounces at lists.jboss.org
[mailto:jboss-development-bounces at lists.jboss.org] On Behalf Of Emmanuel
Bernard
Sent: Wednesday, July 26, 2006 2:52 PM
To: JBoss.org development list
Subject: Re: [JBoss-dev] calling a super method implementation

The reasoning behind that is the EJB3 spec

A class is permitted to override an inherited callback method of the 
same callback type, and in this case, the overridden
method is not invoked. Note that if *a method overrides an inherited 
callback method* but specifies a different lifecycle event or *is not a 
lifecycle callback
method* (ie not annotated), *the overridden method will be invoked*.

Emmanuel Bernard wrote:
>
>
> I don't know how to (or if it's even possible to) call by reflection a

> super implementation of a given method
>
> public class SuperA {
> public void testDisplay() {
>    System.out.println("SuperA");
> }
> }
>
> public class A extends SuperA {
> public void testDisplay() {
>    System.out.println("A");
> }
> }
>
> SuperA.class.getDeclaredMethod("testDisplay", new Class[] 
> {}).invoke(aInstance, new Object[] {});
> will actually display 'A'
>
> I'd like to display 'SuperA'
>
> Any help apreciated
>
>
> _______________________________________________
> jboss-development mailing list
> jboss-development at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/jboss-development
>
_______________________________________________
jboss-development mailing list
jboss-development at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-development




More information about the jboss-development mailing list