java.lang.reflect.Array.set()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中java.lang.reflect.Array.set()方法的一些代码示例,展示了Array.set()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Array.set()方法的具体详情如下:
包路径:java.lang.reflect.Array
类名称:Array
方法名:set

Array.set介绍

[英]Sets the element of the array at the specified index to the value. Equivalent to array[index] = value. If the array component is a primitive type, the value is automatically unboxed.
[中]将指定索引处的数组元素设置为值。相当于数组[索引]=值。如果数组组件是基元类型,则该值将自动取消绑定。

代码示例

代码示例来源:origin: libgdx/libgdx

/** Sets the value of the indexed component in the supplied array to the supplied value. */
static public void set (Object array, int index, Object value) {
  java.lang.reflect.Array.set(array, index, value);
}

代码示例来源:origin: libgdx/libgdx

/** Sets the value of the indexed component in the supplied array to the supplied value. */
static public void set (Object array, int index, Object value) {
  java.lang.reflect.Array.set(array, index, value);
}

代码示例来源:origin: apache/flink

@Override
  public T set(T record, F fieldValue) {
    Array.set(record, pos, fieldValue);
    return record;
  }
}

代码示例来源:origin: neo4j/neo4j

@Override
public void write( Object value )
{
  Array.set( array, index++, value );
}

代码示例来源:origin: neo4j/neo4j

@Override
public void write( Object value )
{
  Array.set( array, index, value );
  index++;
}

代码示例来源: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: neo4j/neo4j

private static <T> T copy( Object[] value, T target )
{
  for ( int i = 0; i < value.length; i++ )
  {
    if ( value[i] == null )
    {
      throw new IllegalArgumentException( "Property array value elements may not be null." );
    }
    Array.set( target, i, value[i] );
  }
  return target;
}

代码示例来源:origin: neo4j/neo4j

@SuppressWarnings( "unchecked" )
public RECORD[] newBatchObject( int batchSize )
{
  Object array = Array.newInstance( klass, batchSize );
  for ( int i = 0; i < batchSize; i++ )
  {
    Array.set( array, i, factory.get() );
  }
  return (RECORD[]) array;
}

代码示例来源: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: org.springframework/spring-context

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: redisson/redisson

/**
 * {@inheritDoc}
 */
public W[] resolve() {
  @SuppressWarnings("unchecked")
  W[] array = (W[]) Array.newInstance(componentType, values.size());
  int index = 0;
  for (AnnotationValue.Loaded<?> annotationValue : values) {
    Array.set(array, index++, annotationValue.resolve());
  }
  return array;
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public Object[] resolve() {
  Object[] array = (Object[]) Array.newInstance(componentType, values.size());
  int index = 0;
  for (AnnotationValue.Loaded<?> annotationValue : values) {
    Array.set(array, index++, annotationValue.resolve());
  }
  return array;
}

代码示例来源:origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public U[] resolve() {
  @SuppressWarnings("unchecked")
  U[] resolved = (U[]) Array.newInstance(unloadedComponentType, values.size());
  int index = 0;
  for (AnnotationValue<?, ?> value : values) {
    Array.set(resolved, index++, value.resolve());
  }
  return resolved;
}

代码示例来源: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: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  String string = (String) source;
  String[] fields = StringUtils.commaDelimitedListToStringArray(string);
  TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
  Assert.state(targetElementType != null, "No target element type");
  Object target = Array.newInstance(targetElementType.getType(), fields.length);
  for (int i = 0; i < fields.length; i++) {
    String sourceElement = fields[i];
    Object targetElement = this.conversionService.convert(sourceElement.trim(), sourceType, targetElementType);
    Array.set(target, i, targetElement);
  }
  return target;
}

代码示例来源:origin: redisson/redisson

/**
 * Sets the array element forced. If index is greater then arrays length, array will be expanded to the index.
 * If speed is critical, it is better to allocate an array with proper size before using this method. 
 */
protected void arrayForcedSet(BeanProperty bp, Object array, int index, Object value) {
  Class componentType = array.getClass().getComponentType();
  array = ensureArraySize(bp, array, componentType, index);
  value = convertType(value, componentType);
  Array.set(array, index, value);
}

代码示例来源:origin: spring-projects/spring-framework

private Object growArrayIfNecessary(Object array, int index, String name) {
  if (!isAutoGrowNestedPaths()) {
    return array;
  }
  int length = Array.getLength(array);
  if (index >= length && index < this.autoGrowCollectionLimit) {
    Class<?> componentType = array.getClass().getComponentType();
    Object newArray = Array.newInstance(componentType, index + 1);
    System.arraycopy(array, 0, newArray, 0, length);
    for (int i = length; i < Array.getLength(newArray); i++) {
      Array.set(newArray, i, newValue(componentType, null, name));
    }
    setPropertyValue(name, newArray);
    Object defaultValue = getPropertyValue(name);
    Assert.state(defaultValue != null, "Default value must not be null");
    return defaultValue;
  }
  else {
    return array;
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@Nullable
public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
  if (source == null) {
    return null;
  }
  Collection<?> sourceCollection = (Collection<?>) source;
  TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
  Assert.state(targetElementType != null, "No target element type");
  Object array = Array.newInstance(targetElementType.getType(), sourceCollection.size());
  int i = 0;
  for (Object sourceElement : sourceCollection) {
    Object targetElement = this.conversionService.convert(sourceElement,
        sourceType.elementTypeDescriptor(sourceElement), targetElementType);
    Array.set(array, i++, targetElement);
  }
  return array;
}

代码示例来源:origin: neo4j/neo4j

private Object array( int length, Class<?> componentType )
{
  Object array = Array.newInstance( componentType, length );
  for ( int i = 0; i < length; i++ )
  {
    Array.set( array, i, createNew( componentType ) );
  }
  return array;
}

代码示例来源:origin: neo4j/neo4j

@Override
public Object read( ReadableClosableChannel from ) throws IOException
{
  ValueType componentType = typeOf( from.get() );
  int length = from.getInt();
  Object value = Array.newInstance( componentType.componentClass(), length );
  for ( int i = 0; i < length; i++ )
  {
    Array.set( value, i, componentType.read( from ) );
  }
  return value;
}

相关文章