java util Iterator java util Array List list

  • Slides: 7
Download presentation

更复杂的例子:时序涉及多个对象 • 使用java. util. Iterator来遍历 java. util. Array. List list = new Array. List<String>();

更复杂的例子:时序涉及多个对象 • 使用java. util. Iterator来遍历 java. util. Array. List list = new Array. List<String>(); for(int i=0; i<10; i++){ list. add(i); } Iterator it = list. iterator(); list. add(10); while(it. has. Next()){ System. out. println(it. next()); } System. out. println(it. next()); 约束 1 调用iterator方法之后,不 能再修改Array. List的内容 正确的使用方式 (如左所示) 约束 2 调用next() 之前必须调用 has. Next()

主要参考文献 • Naeem, N. A. , Lhotak, O. Typestate-like analysis of multiple interacting objects.

主要参考文献 • Naeem, N. A. , Lhotak, O. Typestate-like analysis of multiple interacting objects. OOPSLA '08: Proceedings of the 23 rd ACM SIGPLAN conference on Objectoriented programming systems languages and applications, ACM, 2008, 347 -366 • Bierhoff, K. , Aldrich, J. Modular typestate checking of aliased objects. OOPSLA '07: Proceedings of the 22 nd annual ACM SIGPLAN conference on Object-oriented programming systems and applications, ACM, 2007, 301 -320