Skip to content

Commit b72870d

Browse files
committed
Rename canCast to canAssign
1 parent 8719512 commit b72870d

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

src/main/java/org/scijava/util/ConversionUtils.java

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,34 @@ 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 canAssign(final Class<?> src, final Class<?> dest) {
108+
return canCast(src, dest);
109+
}
110+
111+
/**
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+
*
116+
* @return true If the destination class is assignable from the source
117+
* object's class, or if the source object is null and destionation
118+
* class is non-null.
119+
*/
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
107128
public static boolean canCast(final Class<?> src, final Class<?> dest) {
108129
if (dest == null) return false;
109130
if (src == null) return true;
@@ -113,13 +134,9 @@ public static boolean canCast(final Class<?> src, final Class<?> dest) {
113134
}
114135

115136
/**
116-
* Checks whether the given object can be cast to the specified type.
117-
*
118-
* @return true If the destination class is assignable from the source
119-
* object's class, or if the source object is null and destionation
120-
* class is non-null.
121-
* @see #cast(Object, Class)
137+
* @deprecated use {@link #canAssign(Object, Class)} instead
122138
*/
139+
@Deprecated
123140
public static boolean canCast(final Object src, final Class<?> dest) {
124141
if (dest == null) return false;
125142
return src == null || canCast(src.getClass(), dest);

0 commit comments

Comments
 (0)