@@ -256,40 +256,44 @@ public Object get(String key) {
256
256
}
257
257
258
258
/**
259
- * Typesafe getter for the value represented by the provided key, with cast to given class.
260
- *
259
+ * Typesafe getter for the value represented by the provided key, with cast to given
260
+ * class.
261
261
* @param key The key to get a value for
262
- * @param clazz The class of return type
262
+ * @param type The class of return type
263
263
* @param <V> Type of returned value
264
- * @return The value of given type represented by the given key or {@code null} if the key
265
- * is not present
264
+ * @return The value of given type represented by the given key or {@code null} if the
265
+ * key is not present
266
266
*/
267
267
@ Nullable
268
- public <V > V get (String key , Class <V > clazz ) {
268
+ public <V > V get (String key , Class <V > type ) {
269
269
Object value = this .map .get (key );
270
270
if (value == null ) {
271
271
return null ;
272
272
}
273
- return get (key , clazz , null );
273
+ return get (key , type , null );
274
274
}
275
275
276
276
/**
277
- * Typesafe getter for the value represented by the provided key, with cast to given class.
278
- *
277
+ * Typesafe getter for the value represented by the provided key, with cast to given
278
+ * class.
279
279
* @param key The key to get a value for
280
280
* @param type The class of return type
281
281
* @param defaultValue Default value in case element is not present
282
282
* @param <V> Type of returned value
283
- * @return The value of given type represented by the given key or {@code null} if the key
284
- * is not present
283
+ * @return The value of given type represented by the given key or the default value
284
+ * if the key is not present
285
285
*/
286
286
@ Nullable
287
- public <V > V get (String key , Class <V > clazz , @ Nullable V defaultValue ) {
287
+ public <V > V get (String key , Class <V > type , @ Nullable V defaultValue ) {
288
288
Object value = this .map .get (key );
289
289
if (value == null ) {
290
290
return defaultValue ;
291
291
}
292
- return clazz .cast (value );
292
+ if (!type .isInstance (value )) {
293
+ throw new ClassCastException ("Value for key=[" + key + "] is not of type: [" + type + "], it is [" + "("
294
+ + value .getClass () + ")" + value + "]" );
295
+ }
296
+ return type .cast (value );
293
297
}
294
298
295
299
/**
0 commit comments