Tabnine Logo
Array.newInstance
Code IndexAdd Tabnine to your IDE (free)

How to use
newInstance
method
in
java.lang.reflect.Array

Best Java code snippets using java.lang.reflect.Array.newInstance (Showing top 20 results out of 28,044)

origin: apache/incubator-dubbo

protected Object[] createArray(int length) {
  if (_componentType != null)
    return (Object[]) Array.newInstance(_componentType, length);
  else
    return new Object[length];
}
origin: libgdx/libgdx

/** Creates a new array with the specified component type and length. */
static public Object newInstance (Class c, int size) {
  return java.lang.reflect.Array.newInstance(c, size);
}
origin: libgdx/libgdx

/** Creates a new array with the specified component type and length. */
static public Object newInstance (Class c, int size) {
  return java.lang.reflect.Array.newInstance(c, size);
}
origin: google/guava

/** Returns the {@code Class} object of arrays with {@code componentType}. */
static Class<?> getArrayClass(Class<?> componentType) {
 // TODO(user): This is not the most efficient way to handle generic
 // arrays, but is there another way to extract the array class in a
 // non-hacky way (i.e. using String value class names- "[L...")?
 return Array.newInstance(componentType, 0).getClass();
}
origin: spring-projects/spring-framework

private Class<?> makeArrayIfNecessary(Class<?> clazz) {
  if (this.dimensions != 0) {
    for (int i = 0; i < this.dimensions; i++) {
      Object array = Array.newInstance(clazz, 0);
      clazz = array.getClass();
    }
  }
  return clazz;
}
origin: apache/incubator-dubbo

public ArrayDeserializer(Class componentType) {
  _componentType = componentType;
  if (_componentType != null) {
    try {
      _type = Array.newInstance(_componentType, 0).getClass();
    } catch (Exception e) {
    }
  }
  if (_type == null)
    _type = Object[].class;
}
origin: google/guava

/**
 * Returns a new array of the given length with the same type as a reference array.
 *
 * @param reference any array of the desired type
 * @param length the length of the new array
 */
static <T> T[] newArray(T[] reference, int length) {
 Class<?> type = reference.getClass().getComponentType();
 // the cast is safe because
 // result.getClass() == reference.getClass().getComponentType()
 @SuppressWarnings("unchecked")
 T[] result = (T[]) Array.newInstance(type, length);
 return result;
}
origin: google/guava

private static <T> T createEmptyArray(Class<T> arrayType) {
 return arrayType.cast(Array.newInstance(arrayType.getComponentType(), 0));
}
origin: spring-projects/spring-framework

private void addToClassHierarchy(int index, Class<?> type, boolean asArray,
    List<Class<?>> hierarchy, Set<Class<?>> visited) {
  if (asArray) {
    type = Array.newInstance(type, 0).getClass();
  }
  if (visited.add(type)) {
    hierarchy.add(index, type);
  }
}
origin: spring-projects/spring-framework

private Object convertDataArrayToTargetArray(Object[] array, Class<?> targetClass) throws NoSuchMethodException {
  Class<?> targetType = targetClass.getComponentType();
  Method fromMethod = targetType.getMethod("from", array.getClass().getComponentType());
  Object resultArray = Array.newInstance(targetType, array.length);
  for (int i = 0; i < array.length; i++) {
    Array.set(resultArray, i, ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
  }
  return resultArray;
}
origin: org.mockito/mockito-core

  Object returnValueFor(Class<?> type) {
    if (type == String.class) {
      return "";
    }  else if (type.isArray()) {
      Class<?> componentType = type.getComponentType();
      return Array.newInstance(componentType, 0);
    }
    return null;
  }
}
origin: google/guava

/**
 * Returns a new array of the given length with the specified component type.
 *
 * @param type the component type
 * @param length the length of the new array
 */
@GwtIncompatible // Array.newInstance(Class, int)
@SuppressWarnings("unchecked")
public static <T> T[] newArray(Class<T> type, int length) {
 return (T[]) Array.newInstance(type, length);
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
private static <T> T[] copyPropertiesToBeanArray(Collection<? extends Annotation> anns, Class<T> beanClass) {
  T[] beans = (T[]) Array.newInstance(beanClass, anns.size());
  int i = 0;
  for (Annotation ann : anns) {
    beans[i++] = copyPropertiesToBean(ann, beanClass);
  }
  return beans;
}
origin: spring-projects/spring-framework

/**
 * For each element in the managed array, resolve reference if necessary.
 */
private Object resolveManagedArray(Object argName, List<?> ml, Class<?> elementType) {
  Object resolved = Array.newInstance(elementType, ml.size());
  for (int i = 0; i < ml.size(); i++) {
    Array.set(resolved, i,
        resolveValueIfNecessary(new KeyedArgName(argName, i), ml.get(i)));
  }
  return resolved;
}
origin: google/guava

/**
 * Returns a two-dimensional array with the table contents. The row and column indices correspond
 * to the positions of the row and column in the iterables provided during table construction. If
 * the table lacks a mapping for a given row and column, the corresponding array element is null.
 *
 * <p>Subsequent table changes will not modify the array, and vice versa.
 *
 * @param valueClass class of values stored in the returned array
 */
@GwtIncompatible // reflection
public V[][] toArray(Class<V> valueClass) {
 @SuppressWarnings("unchecked") // TODO: safe?
 V[][] copy = (V[][]) Array.newInstance(valueClass, rowList.size(), columnList.size());
 for (int i = 0; i < rowList.size(); i++) {
  System.arraycopy(array[i], 0, copy[i], 0, array[i].length);
 }
 return copy;
}
origin: spring-projects/spring-framework

/**
 * Return a {@link ResolvableType} as a array of the specified {@code componentType}.
 * @param componentType the component type
 * @return a {@link ResolvableType} as an array of the specified component type
 */
public static ResolvableType forArrayComponent(ResolvableType componentType) {
  Assert.notNull(componentType, "Component type must not be null");
  Class<?> arrayClass = Array.newInstance(componentType.resolve(), 0).getClass();
  return new ResolvableType(arrayClass, null, null, componentType);
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
  Assert.state(targetElementType != null, "No target element type");
  Object target = Array.newInstance(targetElementType.getType(), 1);
  Object targetElement = this.conversionService.convert(source, sourceType, targetElementType);
  Array.set(target, 0, targetElement);
  return target;
}
origin: org.mockito/mockito-core

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] typedArray) {
  T[] array = typedArray.length >= size() ? typedArray : (T[]) newInstance(typedArray.getClass().getComponentType(), size());
  return unwrapTo(array);
}
origin: spring-projects/spring-framework

@Nullable
private Class<?> resolveClass() {
  if (this.type == EmptyType.INSTANCE) {
    return null;
  }
  if (this.type instanceof Class) {
    return (Class<?>) this.type;
  }
  if (this.type instanceof GenericArrayType) {
    Class<?> resolvedComponent = getComponentType().resolve();
    return (resolvedComponent != null ? Array.newInstance(resolvedComponent, 0).getClass() : null);
  }
  return resolveType().resolve();
}
origin: jenkinsci/jenkins

@Override
@SuppressWarnings("unchecked") // cast to T[]
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
  setInstallations(req.bindJSONToList(clazz, json.get("tool")).toArray((T[]) Array.newInstance(clazz, 0)));
  return true;
}
java.lang.reflectArraynewInstance

Javadoc

Returns a new array of the specified component type and length. Equivalent to new componentType[size].

Popular methods of Array

  • getLength
    Returns the length of the specified array object, as an int.
  • get
    Returns the value of the indexed component in the specified array object. The value is automatically
  • set
    Sets the value of the indexed component of the specified array object to the specified new value. Th
  • setInt
    Sets the value of the indexed component of the specified array object to the specified int value.
  • setDouble
    Sets the value of the indexed component of the specified array object to the specified double value.
  • setFloat
    Sets the value of the indexed component of the specified array object to the specified float value.
  • setLong
    Sets the value of the indexed component of the specified array object to the specified long value.
  • setShort
    Sets the value of the indexed component of the specified array object to the specified short value.
  • setBoolean
    Sets the value of the indexed component of the specified array object to the specified boolean value
  • setByte
    Sets the value of the indexed component of the specified array object to the specified byte value.
  • setChar
    Sets the value of the indexed component of the specified array object to the specified char value.
  • getDouble
    Returns the value of the indexed component in the specified array object, as a double.
  • setChar,
  • getDouble,
  • getInt,
  • getLong,
  • getFloat,
  • getByte,
  • getBoolean,
  • getShort,
  • getChar

Popular in Java

  • Start an intent from android
  • addToBackStack (FragmentTransaction)
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • BasicDataSource (org.apache.commons.dbcp)
    Basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. This is no
  • Logger (org.apache.log4j)
    This is the central class in the log4j package. Most logging operations, except configuration, are d
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now