Java Type getImplInstance(Class<? extends Type> clazz)

PreviousNext

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 SunGard CSA LLC and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://   w   ww   .  d   e  m  o 2   s.   c  o   m
 *    SunGard CSA LLC - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.lang.reflect.Type;

public class Main {
    private static Object getImplInstance(Class<? extends Type> clazz) {
        if (!clazz.isInterface()) {
            try {
                return clazz.newInstance();
            } catch (InstantiationException e) {
                throw new UnsupportedOperationException(e);
            } catch (IllegalAccessException e) {
                throw new UnsupportedOperationException(e);
            }
        } else {
            throw new UnsupportedOperationException(clazz.getName());
        }
    }
}
PreviousNext

Related