All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.invation.code.toval.reflect.GenericReflection Maven / Gradle / Ivy

Go to download

TOVAL comprises a set of java classes for common programming issues. It includes utils for arrays, lists, sets and collections for convenient handling and modification, but also support for mathematic definitions concerning logic (clauses + resolution) together with some algorithms for permutations, powersets and resolution. Additionally it contains a number of types for multisets, matrices with object keys and much more.

The newest version!
package de.invation.code.toval.reflect;

import java.lang.reflect.InvocationTargetException;

public class GenericReflection {

	@SuppressWarnings("unchecked")
	public static  T newInstance(T obj) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
		Object newobj = obj.getClass().getConstructor().newInstance();
		return (T) newobj;
	}

	@SuppressWarnings("unchecked")
	public static  T newInstance(Class classType) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
		Object newobj = classType.getConstructor().newInstance();
		return (T) newobj;
	}

	@SuppressWarnings("unchecked")
	public static  Class getComponentType(T[] a) {
		Class k = a.getClass().getComponentType();
		return (Class) k;
	}

	@SuppressWarnings("unchecked")
	public static  T[] newArray(Class k, int size) {
		if (k.isPrimitive())
			throw new IllegalArgumentException("Argument cannot be primitive: " + k);
		Object a = java.lang.reflect.Array.newInstance(k, size);
		return (T[]) a;
	}

	public static  T[] newArray(T[] a, int size) {
		return newArray(getComponentType(a), size);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy