Skip to content

Commit

Permalink
Fixed a bug in ObjectUtils.tryCastAs where arguments were swapped
Browse files Browse the repository at this point in the history
  • Loading branch information
Aklakan committed Sep 30, 2023
1 parent 34bc059 commit b10c215
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ public static String toStringWithIdentityHashCode(Object obj, String nullDefault
return obj != null ? obj.getClass().getName() + "@" + System.identityHashCode(obj) : nullDefault;
}

/**
* Check if the given object can be assigned to given class.
* Also works for primitive types, e.g. int can be assigned to Long.
*
* @implNote
* Relies on {@link ClassUtils#isAssignable(Class, Class)}
*/
public static boolean canCastAs(Class<?> clazz, Object o) {
boolean result = o == null ? true : ClassUtils.isAssignable(clazz, o.getClass());
boolean result = o == null ? true : ClassUtils.isAssignable(o.getClass(), clazz);
return result;
}

Expand Down

0 comments on commit b10c215

Please sign in to comment.