
org.solovyev.common.factory.Factory Maven / Gradle / Ivy
The newest version!
package org.solovyev.common.factory;
/**
* User: serso
* Date: 31.03.2009
* Time: 20:21:42
*/
public class Factory {
@SuppressWarnings("unchecked")
public static T[] getArrayOf(Class klass, int length){
Object[] array = null;
try {
if ( length > 0 ) {
array = new Object[length];
for ( int i = 0; i < array.length; i++ ) {
array[i] = klass.newInstance();
}
}
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return (T[])array;
}
public static T newInstance(Class klass) {
T result = null;
try {
result = klass.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy