文章目录
3·18
主要了解了MIT中 immutable和mutable数据类型的区别。
Primitives | Objective Reference Types |
---|---|
int,long, byte, short, char, float, double, boolean | Classes, interfaces, arrays, enums, annotations |
No indentity except their value | Have identity distinct from value |
Immutable | Some mutable, some not |
On stack, exist only when in use | On heap, garbage collected |
Can’t achieve unity of expression | Unity of expression with generics |
Dirt cheap | More costly |
此外,也学习了mutability和immutability。迭代器Iterator,对应强调for循环
List<String> lst = ...;
for (String str : lst) {
System.out.println(str);
}
而用迭代器的话,如下所示:
List<String> lst = ...;
Iterator iter = lst.iterator();
while (iter.hasNext()) {
String str = iter.next();
System.out.println(str);
}