[infinispan-commits] Infinispan SVN: r780 - trunk/core/src/main/java/org/infinispan/util.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Sep 4 10:42:28 EDT 2009


Author: galder.zamarreno at jboss.com
Date: 2009-09-04 10:42:28 -0400 (Fri, 04 Sep 2009)
New Revision: 780

Modified:
   trunk/core/src/main/java/org/infinispan/util/Immutables.java
Log:
Actually, using bounded wilcards for return types is not recommended since it forces clients to deal with them directly. Instead, add casts in the method implementations.

Modified: trunk/core/src/main/java/org/infinispan/util/Immutables.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/util/Immutables.java	2009-09-04 14:32:57 UTC (rev 779)
+++ trunk/core/src/main/java/org/infinispan/util/Immutables.java	2009-09-04 14:42:28 UTC (rev 780)
@@ -78,10 +78,10 @@
     * @param list the list to copy
     * @return the immutable copy
     */
-   public static <T> List<? extends T> immutableListCopy(List<? extends T> list) {
+   public static <T> List<T> immutableListCopy(List<? extends T> list) {
       if (list == null) return null;
       if (list.isEmpty()) return Collections.emptyList();
-      if (list.size() == 1) return Collections.singletonList(list.get(0));
+      if (list.size() == 1) return (List<T>) Collections.singletonList(list.get(0));
       return new ImmutableListCopy<T>(list);
    }
 
@@ -133,10 +133,10 @@
     * @param set the set to copy from
     * @return an immutable set copy
     */
-   public static <T> Set<? extends T> immutableSetCopy(Set<? extends T> set) {
+   public static <T> Set<T> immutableSetCopy(Set<? extends T> set) {
       if (set == null) return null;
       if (set.isEmpty()) return Collections.emptySet();
-      if (set.size() == 1) return Collections.singleton(set.iterator().next());
+      if (set.size() == 1) return (Set<T>) Collections.singleton(set.iterator().next());
       Set<? extends T> copy = ObjectDuplicator.duplicateSet(set);
       if (copy == null)
          // Set uses Collection copy-ctor
@@ -164,12 +164,12 @@
     * @param map the map to copy from
     * @return an immutable map copy
     */
-   public static <K, V> Map<? extends K, ? extends V> immutableMapCopy(Map<? extends K, ? extends V> map) {
+   public static <K, V> Map<K, V> immutableMapCopy(Map<? extends K, ? extends V> map) {
       if (map == null) return null;
       if (map.isEmpty()) return Collections.emptyMap();
       if (map.size() == 1) {
          Map.Entry<? extends K, ? extends V> me = map.entrySet().iterator().next();
-         return Collections.singletonMap(me.getKey(), me.getValue());
+         return (Map<K, V>) Collections.singletonMap(me.getKey(), me.getValue());
       }
 
       Map<? extends K, ? extends V> copy = ObjectDuplicator.duplicateMap(map);
@@ -188,10 +188,10 @@
     * @param collection the collection to copy
     * @return an immutable copy
     */
-   public static <T> Collection<? extends T> immutableCollectionCopy(Collection<? extends T> collection) {
+   public static <T> Collection<T> immutableCollectionCopy(Collection<? extends T> collection) {
       if (collection == null) return null;
       if (collection.isEmpty()) return Collections.emptySet();
-      if (collection.size() == 1) return Collections.singleton(collection.iterator().next());
+      if (collection.size() == 1) return (Collection<T>) Collections.singleton(collection.iterator().next());
 
       Collection<? extends T> copy = ObjectDuplicator.duplicateCollection(collection);
       if (copy == null)



More information about the infinispan-commits mailing list