1.ArrayList在确定长度的时候,list的size可以赋值

2.添加class Null判断
master
星期八 5 years ago
parent d807557d5f
commit 2924b6e184
  1. 5
      panda-beans/src/main/java/org/panda/beans/util/BeanUtil.java

@ -1,6 +1,7 @@
package org.panda.beans.util; package org.panda.beans.util;
import com.sun.tools.javac.util.Assert;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -27,8 +28,8 @@ public class BeanUtil {
*/ */
public static List<Field> getAllField(Class clazz){ public static List<Field> getAllField(Class clazz){
Field[] fields = getField(clazz); Field[] fields = getField(clazz);
List<Field> fieldList = new ArrayList<>();
Field[] superFields = getSuperField(clazz); Field[] superFields = getSuperField(clazz);
List<Field> fieldList = new ArrayList<>(fields.length+superFields.length);
if (superFields!=null&&superFields.length>0){ if (superFields!=null&&superFields.length>0){
for (Field field:superFields) { for (Field field:superFields) {
fieldList.add(field); fieldList.add(field);
@ -217,6 +218,7 @@ public class BeanUtil {
*/ */
public static <T> T instantiateClass(Class<T> clazz){ public static <T> T instantiateClass(Class<T> clazz){
T t = null; T t = null;
Assert.checkNonNull(clazz);
try { try {
t = clazz.newInstance(); t = clazz.newInstance();
} catch (InstantiationException e) { } catch (InstantiationException e) {
@ -237,6 +239,7 @@ public class BeanUtil {
*/ */
public static <T> T instantiateClass(Class<T> clazz,Object... params){ public static <T> T instantiateClass(Class<T> clazz,Object... params){
T t = null; T t = null;
Assert.checkNonNull(clazz);
Class[] classes = new Class[params.length]; Class[] classes = new Class[params.length];
for (int i=0;i<params.length;i++){ for (int i=0;i<params.length;i++){
classes[i] = params[i].getClass(); classes[i] = params[i].getClass();

Loading…
Cancel
Save