@SuppressWarnings("unchecked")
private<T> T returnExistingWithCast(MutableMetric metric,
Class<T> metricClass, String name) {
if (!metricClass.isAssignableFrom(metric.getClass())) {
throw new MetricsException("Metric already exists in registry for metric name: " +
name + " and not of type " + metricClass +
" but instead of type " + metric.getClass());
}
return (T) metric;