我有一个问题,无法解决它。
我在类的方法中将整数分配a
给成员。dataAction
setDataAction(int a)
Action
分配后的值仍然不同!a == -3
, dataAction == 0
. Eclipse 和 Java 都没有引起任何错误或抱怨。
环境: Win7-64 与 Eclipse Juno 和 JDK-7u25-win-64。
为了防止在这个方向上发表任何评论,分配是在类的一个实例上完成的。我已经在几台机器上尝试过,甚至设置了一台绝对没有病毒的原始机器,只有操作系统和环境!
调试器屏幕截图的更好图片也可以在以下位置获得: http://setosix.eu/Java_Assignment_Problem.jpg / .gif / .png
// Class to hold return values of the applet to determine further action
class Action implements Constants {
int dataAction;
int appletAction;
int dataResult;
Action() {
dataAction = MOVE_NOT;
appletAction = ACT_CONTINUE;
dataResult = LV_OK;
}
public void setDataAction(int a) {
dataAction = a;
}
}
// here the 'Action' instance is created
public class TableResource extends Database {
private Connection dbLink;
private Statement stmt;
protected ResultSet rs;
// hold the return values of applet
protected Action nextAction;
protected TableResource() {
dbLink = getInstance().getConnection();
rs = null;
stmt = null;
nextAction = new Action();
}
...
// data class for 'AppletMandanten'
public class DataMandanten extends TableResource implements Data {
...
// constants are defined here
public interface Constants {
// constants defining moves in record-/browse-mode
public static final int MOVE_NOT = 0;
public static final int MOVE_FIRST = -1;
public static final int MOVE_LAST = -2;
public static final int MOVE_NEXT = -3;
public static final int MOVE_PREVIOUS = -4;
public static final int MOVE_NEXTPAGE = -5;
public static final int MOVE_PREVPAGE = -6;
...
// interface ‘Data’ extends interface ‘Constants’
public interface Data extends Constants {
...
// in this class the instance ‘data’ is creates
public class ModulMandanten extends EventHandler implements Data {
...
// main control of applet
public int control() {
int leave = LV_OK;
DataMandanten data;
// connect to database
db = Database.getInstance();
if( db.dbConnect() < 0 ) {
Intelligence.out( 1, "ERROR in ("+"RWG"+"): Failed to connect to Server!");
leave = LV_ERROR;
}
// here ‘data’ instance is created
data = new DataMandanten();
...
public abstract class Applet extends ModulMandanten {
...
// here the invocation takes place
public class AppletMandanten extends Applet {
...
// handle events in class ‘AppleMandanten’ (derives from ‘ActionPerformed()’
private void eventHandler( ActionEvent event ) {
...
// invocation is called in method 'eventHandler', class 'AppletMandanten'
switch (eventName){
case ("btnNext"): {
// 'next' button pressed
data.nextAction.setDataAction( MOVE_NEXT );
// alternatively: doesn't work neither
data.nextAction.setDataAction = MOVE_NEXT;
// 'data.nextAction.setDataAction' printed to console ( != MOVE_NEXT )
System.out.println(Integer.toString(data.nextAction.dataAction));
break;
// !!! after this 'dataAction' isn't touched again !!!
}
...
Eclipse 调试模式下的 Java 分配问题 http://setosix.eu/Java_Assignment_Problem.jpg