Generische Polymorphie

generische Methode:

static <E> int length (Collection<E> c) {
  int n = 0; for (E x : c) {n++}; return n;
}
hierbei ist E eine Typvariable

Bei Benutzung

Collection<String> text =
    Arrays.asList (new String [] { "foo", "bar" });
System.out.println (length (text));
wird Typvariable instantiiert (durch einen konkreten Typ ersetzt).



Johannes Waldmann 2009-01-22