Author: limpbizkit
Date: Thu May  7 12:15:22 2009
New Revision: 941

Modified:
    trunk/src/com/google/inject/TypeLiteral.java
    trunk/src/com/google/inject/util/Types.java

Log:
additional doc for TypeLiteral, helping to make it easier to find wildcard  
types.

Modified: trunk/src/com/google/inject/TypeLiteral.java
==============================================================================
--- trunk/src/com/google/inject/TypeLiteral.java        (original)
+++ trunk/src/com/google/inject/TypeLiteral.java        Thu May  7 12:15:22 2009
@@ -45,8 +45,21 @@
   * <p>
   * {...@code TypeLiteral<List<String>> list = new TypeLiteral<List<String>>() 
 
{};}
   *
- * <p>Assumes that type {...@code T} implements {...@link Object#equals} and
- * {...@link Object#hashCode()} as value (as opposed to identity) comparison.
+ * <p>This syntax cannot be used to create type literals that have wildcard
+ * parameters, such as {...@code Class<?>} or {...@code List<? extends  
CharSequence>}.
+ * Such type literals must be constructed programatically, either by {...@link
+ * Method#getGenericReturnType extracting types from members} or by using  
the
+ * {...@link Types} factory class.
+ *
+ * <p>Along with modeling generic types, this class can resolve type  
parameters.
+ * For example, to figure out what type {...@code keySet()} returns on a  
{...@code
+ * Map<Integer, String>}, use this code:<pre>   {...@code
+ *
+ *   TypeLiteral<Map<Integer, String>> mapType
+ *       = new TypeLiteral<Map<Integer, String>>() {};
+ *   TypeLiteral<?> keySetType
+ *       = mapType.getReturnType(Map.class.getMethod("keySet"));
+ *   System.out.println(keySetType); // prints "Set<Integer>"}</pre>
   *
   * @author [email protected] (Bob Lee)
   * @author [email protected] (Jesse Wilson)

Modified: trunk/src/com/google/inject/util/Types.java
==============================================================================
--- trunk/src/com/google/inject/util/Types.java (original)
+++ trunk/src/com/google/inject/util/Types.java Thu May  7 12:15:22 2009
@@ -72,13 +72,18 @@

    /**
     * Returns a type that represents an unknown type that extends {...@code  
bound}.
+   * For example, if {...@code bound} is {...@code CharSequence.class}, this  
returns
+   * {...@code ? extends CharSequence}. If {...@code bound} is {...@code  
Object.class},
+   * this returns {...@code ?}, which is shorthand for {...@code ? extends  
Object}.
     */
    public static WildcardType subtypeOf(Type bound) {
      return new WildcardTypeImpl(new Type[] { bound },  
MoreTypes.EMPTY_TYPE_ARRAY);
    }

    /**
-   * Returns a type that represents an unknown supertype of {...@code bound}.
+   * Returns a type that represents an unknown supertype of {...@code bound}.  
For
+   * example, if {...@code bound} is {...@code String.class}, this returns  
{...@code ?
+   * super String}.
     */
    public static WildcardType supertypeOf(Type bound) {
      return new WildcardTypeImpl(new Type[] { Object.class }, new Type[] {  
bound });

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to