Here you can find the source of newInstance(Field field)
Parameter | Description |
---|---|
field | field to get type |
public static Object newInstance(Field field)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { /**/*from ww w. j a v a2 s . co m*/ * Get type of field and create an instance to that type * * @param field field to get type * @return an instance of field's type */ public static Object newInstance(Field field) { try { return field.getType().newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Can not new an instance of class " + field.getType() + " for field " + field.getName() + " on class " + field.getDeclaringClass(), e); } } }