2

Why trying to invoke

try {
    method.invoke(super, "abc", "def");
}
catch (Exception e) {
    // ignore for now
}

gives me such an error:

'.' expected

In Netbeans 7.2.1? After clean&build:

Compiling 2 source files to C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\build\web\WEB-INF\classes
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\src\java\pl\adrian\servlets\ServletPlus.java:45: error: '.' expected
                    method.invoke(super, "abc", "def");
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\src\java\pl\adrian\servlets\ServletPlus.java:45: error: ')' expected
                    method.invoke(super, "abc", "def");
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\src\java\pl\adrian\servlets\ServletPlus.java:45: error: ';' expected
                    method.invoke(super, "abc", "def");
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\src\java\pl\adrian\servlets\ServletPlus.java:45: error: not a statement
                    method.invoke(super, "abc", "def");
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\src\java\pl\adrian\servlets\ServletPlus.java:45: error: ';' expected
                    method.invoke(super, "abc", "def");
5 errors
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\nbproject\build-impl.xml:851: The following error occurred while executing this line:
C:\Documents and Settings\u\Moje dokumenty\NetBeansProjects\ServletPlus\nbproject\build-impl.xml:284: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 3 seconds)
Adrian Adamczyk
  • 3,000
  • 5
  • 25
  • 41
  • 1
    Compilation failed in `ServletPlus.java`, line 45 – Ilya Oct 09 '13 at 10:57
  • Hi,@Adrian Adamczyk you asked this question http://gamedev.stackexchange.com/questions/51231/andengine-box2d-high-speed-body-overlapping-prismatic-joints?rq=1 (How you drawn the path please please help me) – Andy Dec 03 '13 at 10:24
  • @Bashir I've used a lot of TexuredPolygon – Adrian Adamczyk Dec 03 '13 at 18:22

4 Answers4

3

super is a reserved word in java.

Try changing the variable name.

See here how you can use the super keyword. http://docs.oracle.com/javase/tutorial/java/IandI/super.html

If you want to invoke a superclass method you have to use super.methodName()

Community
  • 1
  • 1
MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
2

I belive you are not doin it right : fyi example of how to invoke a method using java reflection :

java.lang.reflect.Method method;

try {
  method = obj.getClass().getMethod(methodName, param1.class, param2.class, ..);
} catch (SecurityException e) {
  // ...
} catch (NoSuchMethodException e) {
  // ...
}

try {
    method.invoke(obj, arg1, arg2,...);
}

EDIT:

And also as @MaVRoSCyhas mentioned super is a key word in java

codeMan
  • 5,730
  • 3
  • 27
  • 51
0

Replace <classInstance> with the name of your class.

Method m = <classInstance>.getClass().getSuperClass().getDeclaredMethod("ABC");
m.invoke(<classInstance>);
svager
  • 769
  • 5
  • 13
  • 32
0

The problem was in my bad understanding of polymorphism, well, it's a bit pitful, because I thought that "super" refers to superclass' object, and "this" to current object - something like that.

Of course, there's only one object which is instanced out of extending class. So I had to replace "super" with "this".

Adrian Adamczyk
  • 3,000
  • 5
  • 25
  • 41