@Test public void test4() { MyObject mo = new MyObject(); mo.str = "test4"; List<Object> list = new ArrayList<Object>(); list.add(mo); TestUtil.sp(list); TestUtil.sp(list.toArray(new String[] {})); }
/** Test: Can String in Object be modified by reference? Result: Yes */ @Test public void test1() { ArrayList<MyObject> mys = new ArrayList<ListTest.MyObject>(); MyObject mo = new MyObject(); mo.str = "init set"; mys.add(mo); TestUtil.sp(mys); mo.str = "first set"; TestUtil.sp(mys); }
/** * Test: Can parameter modified by Method? Result: Properties can be modified, but can't set * parameter to null */ @Test public void test3() { MyObject mo = new MyObject(); mo.str = "lala"; TestUtil.sp("Init - " + mo); test3_method(mo); TestUtil.sp("Change Property - " + mo); mo.str = "tonull"; test3_method(mo); TestUtil.sp("Set Object to null - " + mo); }
/** Test: Can enum in Object be modified by reference? Result: No, value type */ @Test public void test2() { MyObject mo = new MyObject(); mo.type = MyType.T1; TestUtil.sp(mo); @SuppressWarnings("unused") MyType t = mo.type; t = null; TestUtil.sp(mo); t = MyType.T2; TestUtil.sp(mo); }
public void test3_method(MyObject obj) { if (obj.str.equals("tonull")) { TestUtil.sp("set obj to null"); obj = null; } else { obj.str = "changed"; } }
@Test public void sortT5() { List<MyObject> mol = ListUtil.newArrayList(new MyObject("b"), new MyObject("a"), new MyObject("c")); TestUtil.sp(mol); Collections.sort(mol, new MyObjectComparator()); TestUtil.sp(mol); // List<String> listNull = null; // Collections.sort(listNull); // TestUtil.sp(listNull); List<String> list = ListUtil.newArrayList("1"); Iterator<String> it = list.iterator(); TestUtil.sp("First : " + it.next()); TestUtil.sp("Second: " + it.next()); }