--- /dev/null
+package test;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class GenericStaticFactory {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ // Parameterized type instance creation with constructor
+ Map<String, List<String>> anagramsRedundancy = new HashMap<String, List<String>>();
+
+ // Parameterized type instance creation with static factory. Without type parameters explicitly
+ // when invoking generic constructors (it is annoying...)
+ Map<String, List<String>> anagrams = newHashMap();
+ }
+
+ public static <K,V> HashMap<K,V> newHashMap() {
+ return new HashMap<K,V>();
+ }
+}
--- /dev/null
+/**
+ *
+ */
+package test;
+
+/**
+ * @author gusarapo
+ *
+ */
+public class SingletonFactory {
+
+ private static UnaryFunction<Object> IDENTITY_FUNCTION =
+ new UnaryFunction<Object>() {
+ public Object apply(Object arg)
+ {
+ return arg;
+ }
+ };
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ String[] strings = {"jute", "hemp", "nylon"};
+ UnaryFunction<String> sameString = identityFunction();
+ for (String s : strings)
+ System.out.println(sameString.apply(s));
+
+ Number [] numbers = {1, 2.0, 3L };
+ UnaryFunction<Number> sameNumber = identityFunction();
+ for (Number n : numbers)
+ System.out.println(sameNumber.apply(n));
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> UnaryFunction<T> identityFunction() {
+ return (UnaryFunction<T>) IDENTITY_FUNCTION;
+ }
+
+}