zoukankan      html  css  js  c++  java
  • 注意java的对象引用

    要注意,当前拿到的“对象引用”, 是不是 指向 最新的实例, 没有的话, 要重新 生成实例去指向。

    代码例子:

      

    AnsweringRuleInfo bhRule = accountGenerator.getAnswerRule(mailboxId, false, AnsweringRuleType.BusinessHours);
                for(int j=0; j<bhRule.getPhones().size();j++){
                    bhRule.getPhones().get(j).setEnabled(false);
                    bhRule.setPhones(Arrays.asList(bhRule.getPhones().get(j)));
                }
                accountGenerator.setAnswerRule(mailboxId, bhRule);

    解析:

    bhRule.getPhones().get(j).setEnabled(false); 操作后, 若不对bRule重新设置 :bhRule.setPhones(Arrays.asList(bhRule.getPhones().get(j)));    (bhRule.getPhones(). 返回List<ForwardPhoneInfo>)

    accountGenerator.setAnswerRule(mailboxId, bhRule) 后, 该account 下ForwardPhoneInfos  各个ForwardPhoneInfo 保持原来的status,映射不到。

            RingGroup ringGroup4;
            ss.getUserCallHandlingComponent().save();
            openCallForwarding(hours);
            ringGroup4 = ss.getUserCallHandlingComponent().getRingGroupByLabel(hours, firstDeskPhoneLabel);
            ArrayList<String> phoneLabels = ringGroup4.getPhoneLabelsInGroup();
            assertEquals(phoneLabels.get(0), firstDeskPhoneLabel, "The ring group include " + firstDeskPhoneLabel);
            assertEquals(phoneLabels.get(1), forwardPhoneNames[1], "The ring group include " + forwardPhoneNames[1]);
            assertEquals(phoneLabels.size(), 2, "The ring group size is 2");
            assertFalse(ringGroup4.isMoveUpButtonEnabled(), "The ringGroup move up button is disable.");
            assertTrue(ringGroup4.isMoveDownButtonEnabled(), "The ringGroup move down button is enable.");
            logBusiness("1.2 Move the group at the middle of list using '\/' arrow > Save > Check arrows for this group at the "Call Handling & Forwarding"");
            ringGroup4.moveGroupDown();
            ringGroup4 = ss.getUserCallHandlingComponent().getRingGroupByLabel(hours, firstDeskPhoneLabel);
            ss.getUserCallHandlingComponent().save();
            openCallForwarding(hours);
            assertTrue(ringGroup4.isMoveUpButtonEnabled(),"The ringGroup move up button is enable.");
            assertTrue(ringGroup4.isMoveDownButtonEnabled(), "The ringGroup move down button is enable.");

     解析:

     对象引用 ringGroup4

    ringGroup4 = ss.getUserCallHandlingComponent().getRingGroupByLabel(hours, firstDeskPhoneLabel);
    获取到第一个位置的ringGroup,

    若 ringGroup4.moveGroupDown();

    此时RingGroup自身类成员发生改变, ss.getUserCallHandlingComponent().getRingGroupByLabel(hours, firstDeskPhoneLabel);获取到的实例也被改变, 而ringGroup4 还是指向原来的对象

    所以此时ringGroup4需要重新指向。

    参考:http://www.2cto.com/kf/201304/199505.html

    student stu1 = new student();

        通常把这条语句的动作称之为创建一个对象,其实,它包含了四个动作。

        1) 右边的"new student" ,是以student 类为模板,在堆空间里创建一个student 类的对象( 也简称为student 对象) 。

        2) 末尾的() 意味着,在对象创建后,立即调用student 类的构造函数,对刚生成的对象进行初始化。

    构造函数是肯定有的。如果你没写,Java 会给你补上一个默认的构造函数。

        3) 左边的"student stu1" 创建了一个student 类引用变量。所谓student 类引用,就是以后可以用来指向某个

        4)"=" 操作符使对象引用指向刚创建的那个student 对象。

  • 相关阅读:
    vfork与fork的区别
    常见的六种设计模式以及应用场景
    Java中常见的集合类比较
    排序——总结
    排序——交换排序
    排序——选择排序
    排序——归并排序
    排序——基数排序
    排序——插入排序
    设计模式
  • 原文地址:https://www.cnblogs.com/jenniferhuang/p/3760841.html
Copyright © 2011-2022 走看看