gpt4 book ai didi

java - Netbeans 7.2.1,Java 反射,method.invoke(super, ..)

转载 作者:行者123 更新时间:2023-11-30 06:22:28 25 4
gpt4 key购买 nike

为什么要调用

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

给我这样的错误:

'.' expected

在 Netbeans 7.2.1 中?清理&构建后:

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)

最佳答案

super 是一个 reserved word in java .

尝试更改变量名称。

在此处查看如何使用 super 关键字。 http://docs.oracle.com/javase/tutorial/java/IandI/super.html

如果你想invoke a superclass method你必须使用 super.methodName()

关于java - Netbeans 7.2.1,Java 反射,method.invoke(super, ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19270049/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com