Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (C) 2011 Tatsuhiro Tsujikawa
  * Permission is hereby granted, free of charge, to any person
  * obtaining a copy of this software and associated documentation
  * files (the "Software"), to deal in the Software without
  * restriction, including without limitation the rights to use, copy,
  * modify, merge, publish, distribute, sublicense, and/or sell copies
  * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
package net.sourceforge.argparse4j.helper;

This class provides helper functions related to reflection.

The application code should not use this class directly.

public final class ReflectHelper {
    private ReflectHelper() {


Convert src to object of type targetType recursively

Convert src to object of type targetType recursively, but it only converts java.util.List to array. If targetType is array type and src is java.util.List, new array is created with the size of src and for each element of src, list2Array(java.lang.Class,java.lang.Object) will be called recursively with the component type of targetType and the element of src. The returned object is assigned to newly created array. If either targetType is not array or src is not java.util.List, simply returns src.

targetType The target type
src The src object
The converted object
    public static Object list2Array(Class<?> targetTypeObject src) {
        if (targetType.isArray() && src instanceof List) {
            List<?> list = (List<?>) src;
            int len = list.size();
            Object dest = Array.newInstance(targetType.getComponentType(), len);
            for (int i = 0; i < len; ++i) {
                        list2Array(targetType.getComponentType(), list.get(i)));
            return dest;
        } else {
            return src;
New to GrepCode? Check out our FAQ X