@@ -178,6 +178,22 @@ public static void setFieldValue(Object obj, String fieldName, Object fieldValue
178178 method .invoke (obj , fieldValue );
179179 }
180180
181+ /**
182+ * Casts the specified value to the required type.
183+ *
184+ * @param value the value to be cast
185+ * @param requiredType the type to which the value should be cast
186+ * @param <T> the type to which the value should be cast
187+ * @return the cast value, or null if the value cannot be cast to the
188+ * required type
189+ */
190+ public static <T > T cast (Object value , Class <T > requiredType ) {
191+ if (requiredType .isInstance (value )) {
192+ return requiredType .cast (value );
193+ }
194+ return null ;
195+ }
196+
181197 /**
182198 * Constructs a method name based on the given prefix and field name.
183199 *
@@ -203,20 +219,4 @@ private static String defaultObject(Object obj) {
203219 return String .valueOf (obj );
204220 }
205221 }
206-
207- /**
208- * Casts the specified value to the required type.
209- *
210- * @param value the value to be cast
211- * @param requiredType the type to which the value should be cast
212- * @param <T> the type to which the value should be cast
213- * @return the cast value, or null if the value cannot be cast to the
214- * required type
215- */
216- public static <T > T cast (Object value , Class <T > requiredType ) {
217- if (requiredType .isInstance (value )) {
218- return requiredType .cast (value );
219- }
220- return null ;
221- }
222222}
0 commit comments