Java Class New Instance newInstanceOf(Class clazz)

Here you can find the source of newInstanceOf(Class clazz)

Description

new Instance Of

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static <T extends Object> T newInstanceOf(Class<T> clazz) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    @SuppressWarnings("unchecked")
    public static <T extends Object> T newInstanceOf(Class<T> clazz) {
        try {/* w  w  w  . jav a 2 s  .  com*/
            if (clazz.equals(byte[].class)) {
                return (T) new byte[] {};
            }
            return clazz.newInstance();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. newInstanceForName(String fullClassName, Object... args)
  2. newInstanceFromClass(final Class clazz)
  3. newInstanceFromClassName(String className, Class classType)
  4. newInstanceFromUnknownArgumentTypes(Class cls, Object[] args)
  5. newInstanceHard(String name)
  6. newInstanceOf(String className)
  7. newInstanceOrThrow(final Class clazz)
  8. newInstancesViaMetaAnnotation(Class declarator, Class metaAnnotationClass, Class expected)
  9. newInstanceViaAnnotation(Class declarator, Annotation annotation, Class expected, Annotation parameter)