COBOL | Java |
---|---|
*> Consuming a generic method via type inference 01 result as type Tuple[binary-long binary-long]. *> Parameters are used to infer type set result to type Tuple::Create(1 2) *> Consuming a generic collection 01 x type List[string] value new List[string]. 01 i binary-long. 01 val string. procedure division. perform varying i from 0 by 1 until i greater than 100 invoke x::Add(i::ToString) end-perform perform varying val through x display val end-perform |
// Consuming a generic method HashMap<Integer, Integer> result; result = new HashMap<Integer, Integer>(1, 2); //Consuming a generic collection List<String> x = new ArrayList<String>(); for(Integer i = 0; i < 101; ++i) { x.add(i.toString()); } for(String val : x) { System.out.println(val); } |
Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.