I have the following generic code:
public V put(K key, V value){
Object o = doOp(ClusterOperation.CONCURRENT_MAP_PUT, key, value);
return (V)o;
}
The thing is, the Object o can be null. When I work with objects like String it is ok to return null cast to String. But when V represents int, then null cast to int throws NullReferenceException.
Is there any solution that is generic enough and handles int’s?
Thanks
Use the
defaultkeyword: