繁体   English   中英

Getter方法返回两个不同的对象identityHashCodes

[英]Getter Method is returning two different objects identityHashCodes

帮助一个项目的朋友,我们尝试调试问题,然后遇到一个更加令人困惑的问题。 我有一个线程通过getter方法获取某个变量的值,并每500ms打印一次其identityHashCode。 一切正常,直到在Game类中更改了变量。 然后,返回的identityHashCode开始在新对象和旧对象之间来回跳转。 那是我从未见过的行为,希望你们对发生的事情有任何建议甚至暗示。

在此先感谢,我附加了部分源代码和控制台输出。

public GamePlayState(int sid) {
            stateID = sid;
            entityManager = StateBasedEntityManager.getInstance();
            game = new Game(this);
            //TEST CODE ONLY
            Thread t = new Thread(this);
            t.start();
    }

    /******TEST CODE ONLY******/
    public synchronized void run () {
            while (true) {
                    System.err.println(System.identityHashCode(game.getShootL()));
                    try {
                            wait(500);
                    } catch (InterruptedException e) {
                            e.printStackTrace();
                    }
            }
    }

产量

611581887
611581887
611581887
611581887
611581887
611581887
现在值已更改
1709366259
611581887
1709366259
611581887
1709366259
611581887
1709366259

到目前为止,我们还没有找到真正的答案,但是将getter方法返回的变量设为静态可以消除该问题。 似乎底层的3rd Party引擎正在混乱对象变量!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM