@@ -97,26 +97,46 @@ public static <T> T cast(final Object src, final Class<T> dest) {
9797 }
9898
9999 /**
100- * Checks whether objects of the given class can be cast to the specified
101- * type.
102- *
100+ * Checks whether objects of the given class can be assigned to the specified
101+ * type. Unlike {@link Class#isAssignableFrom(Class)}, this method considers
102+ * auto-unboxing.
103+ *
103104 * @return true If the destination class is assignable from the source one, or
104105 * if the source class is null and destination class is non-null.
105- * @see #cast(Object, Class)
106106 */
107- public static boolean canCast (final Class <?> src , final Class <?> dest ) {
108- if (dest == null ) return false ;
109- return src == null || dest .isAssignableFrom (src );
107+ public static boolean canAssign (final Class <?> src , final Class <?> dest ) {
108+ return canCast (src , dest );
110109 }
111110
112111 /**
113- * Checks whether the given object can be cast to the specified type.
114- *
112+ * Checks whether the given object can be assigned to the specified type.
113+ * Unlike {@link Class#isAssignableFrom(Class)}, this method considers
114+ * auto-unboxing.
115+ *
115116 * @return true If the destination class is assignable from the source
116117 * object's class, or if the source object is null and destionation
117118 * class is non-null.
118- * @see #cast(Object, Class)
119119 */
120+ public static boolean canAssign (final Object src , final Class <?> dest ) {
121+ return canCast (src , dest );
122+ }
123+
124+ /**
125+ * @deprecated use {@link #canAssign(Class, Class)} instead
126+ */
127+ @ Deprecated
128+ public static boolean canCast (final Class <?> src , final Class <?> dest ) {
129+ if (dest == null ) return false ;
130+ if (src == null ) return true ;
131+ final Class <?> saneSrc = getNonprimitiveType (src );
132+ final Class <?> saneDest = getNonprimitiveType (dest );
133+ return saneDest .isAssignableFrom (saneSrc );
134+ }
135+
136+ /**
137+ * @deprecated use {@link #canAssign(Object, Class)} instead
138+ */
139+ @ Deprecated
120140 public static boolean canCast (final Object src , final Class <?> dest ) {
121141 if (dest == null ) return false ;
122142 return src == null || canCast (src .getClass (), dest );
0 commit comments