Created
June 13, 2011 14:55
-
-
Save karanmalhi/1022918 to your computer and use it in GitHub Desktop.
Testing Generics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package learnquest; | |
import java.util.ArrayList; | |
import java.util.Iterator; | |
public class TestGenerics { | |
public static void main(String[] args) { | |
ArrayList<Number> list = new ArrayList<Number>(); | |
list.add(new Integer(0)); | |
list.add(new Integer(1)); | |
list.add(new Integer(3)); | |
list.add(new Integer(2)); | |
Number number = list.get(0); | |
Object x = list.get(1); | |
Iterator<Number> iterator = list.iterator(); // Ctrl + Shift + O | |
while (iterator.hasNext()) { | |
Number n2 = (Number) iterator.next(); | |
} | |
for (Iterator iterator2 = list.iterator(); iterator2.hasNext();) { | |
Number number2 = (Number) iterator2.next(); | |
} | |
} | |
} | |
// Ctrl + Shift + L |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment