Created
April 3, 2012 08:59
-
-
Save martiner/2290555 to your computer and use it in GitHub Desktop.
Type
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
class Gtype { | |
def list; | |
void write() { | |
list.each { | |
write(it) | |
} | |
} | |
void write(Number n) { | |
println "Number: ${n}" | |
} | |
void write(Integer n) { | |
println "Integer: ${n}" | |
} | |
} | |
new Gtype(list: [1, 1.1]).write() |
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
import java.util.List; | |
import static java.util.Arrays.asList; | |
public class Type { | |
List<? extends Number> list; | |
public Type(List<? extends Number> list) { | |
this.list = list; | |
} | |
private void write() { | |
for (Number i: list) { | |
write(i); | |
} | |
} | |
private void write(Number n) { | |
System.out.println("Number: " + n); | |
} | |
private void write(Integer n) { | |
System.out.println("Integer: " + n); | |
} | |
public static void main(String... args) { | |
new Type(asList(1, 1.1)).write(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment