void (String[] args) { String prefix = "class B<S, R extends S> {}\n" + "abstract class A<T> {\n"; String template = " <K> void baz$N$(B<$K1$, $K2$> a) {}\n" + " abstract B<$T1$,$T2$> foo$N$();\n" + " void bar$N$(A<$A1$> a){\n" + " baz$N$(a.foo$N$());\n" + " }\n"; String suffix = "}"; String[] k = {"K", "? extends K", "? super K", "?"}; String[] t = {"T", "? extends T", "? super T", "?"}; String[] a = {"? extends T", "? super T", "?"}; System.out.println(prefix); int n = 1; for (int ki = 0; ki < k.length; ki++) { String k1 = k[ki]; for (int kki = ki; kki < k.length; kki++) { String k2 = k[kki]; for (int i = 0; i < t.length; i++) { String t1 = t[i]; for (int it = i; it < t.length; it++) { String t2 = t[it]; for (String a1 : a) { System.out.println(); System.out.println( template.replaceAll("\\$K1\\$", k1) .replaceAll("\\$K2\\$", k2) .replaceAll("\\$T1\\$", t1) .replaceAll("\\$T2\\$", t2) .replaceAll("\\$A1\\$", a1) .replaceAll("\\$N\\$", String.valueOf(n++))); } } } } } System.out.println(suffix); }