【发布时间】:2010-10-24 22:26:29
【问题描述】:
我试图理解一些 java 代码,由于某种原因,这些代码似乎执行了它的返回类型类(SQLExecutionInfo 类),而在方法中没有其他任何东西。 也许这就是java的工作方式(即不管方法体中的内容是否首先执行返回的类的类型??)
方法是这样开始的:
protected Query.SQLExecutionInfo compileSingleQDB(StatementExpression statement, boolean keyNeeded) throws StatementException, XMLDBCException {
//body of method
System.out.println("body of method");
}
/*****THE REFERENCED SQLExecutionInfo class is a subclassed within Query.java***********/
public static class SQLExecutionInfo {
public SqlExpression sql = null;
public StatementInfo sInfo = null;
public Mapper mapper = null;
public List childrenQueries = null;
public int[] idPosition = null;
public int idCount = -1;
public SQLExecutionInfo() {
}
public SQLExecutionInfo(SqlExpression sql, Mapper mapper) {
System.out.println("POINT ALPHA2:"+ sql);
this.sql = sql;
this.mapper = mapper;
}
由于某种原因,compileSingleQDB 方法(即主体)中没有任何内容被执行,但是调用了 SQLExecutionInfo 类并调用了 System.out.println("POINT ALPHA2:"+ sql)。
谁能解释一下这是为什么?
谢谢, 巴勃罗
请让我提供更多信息:
这个让我很困惑,
代码执行从这里开始:
System.out.println("POINT SQL:"+jdbcExecInfo.sql); // Returns null at this stage
try {
System.out.println("POINT A");
jdbcExecInfo = compileSingleQDB(((Variable) Qdb.get(0)).getExpression(), false);
System.out.println("POINT B");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("POINT SQL:"+jdbcExecInfo.sql); // Somehow now has a value ????
不知何故,它仍然到达 POINT B,即使我输入:Thread.dumpStack();
and new Error().printStackTrace();
在 compileSingleQDB 方法中什么也没有出现。
即使我删除了 compileSingleQDB 方法的内部结构并将其替换为:
protected Query.SQLExecutionInfo compileSingleQDB(StatementExpression statement, boolean keyNeeded) throws XQueryException, XMLDBCException {
return null;
}
字符串 jdbcExecInfo.sql 仍然以某种方式获取值
【问题讨论】:
-
您声称在任何上下文之外(即作为
main方法中的唯一语句)调用方法compileSingleQDB时没有(有意义的)参数(null 和 false)会导致 SQLExecutionInfo 的构造函数被调用? -
我看不出这段代码是如何编译的。 compileSingleQDB 方法不返回任何内容,它是我的签名所必需的。
标签: java static methods protected