Tabnine Logo
Class.getComponentType
Code IndexAdd Tabnine to your IDE (free)

How to use
getComponentType
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.getComponentType (Showing top 20 results out of 28,305)

origin: google/guava

 @Override
 void visitClass(Class<?> t) {
  result.set(t.getComponentType());
 }
}.visit(type);
origin: stackoverflow.com

 public <T> T[] concatenate (T[] a, T[] b) {
  int aLen = a.length;
  int bLen = b.length;

  @SuppressWarnings("unchecked")
  T[] c = (T[]) Array.newInstance(a.getClass().getComponentType(), aLen+bLen);
  System.arraycopy(a, 0, c, 0, aLen);
  System.arraycopy(b, 0, c, aLen, bLen);

  return c;
}
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: spring-projects/spring-framework

/**
 * Check if the given class represents an array of primitives,
 * i.e. boolean, byte, char, short, int, long, float, or double.
 * @param clazz the class to check
 * @return whether the given class is a primitive array class
 */
public static boolean isPrimitiveArray(Class<?> clazz) {
  Assert.notNull(clazz, "Class must not be null");
  return (clazz.isArray() && clazz.getComponentType().isPrimitive());
}
origin: google/guava

 @Override
 Type usedInGenericType(Type type) {
  checkNotNull(type);
  if (type instanceof Class) {
   Class<?> cls = (Class<?>) type;
   if (cls.isArray()) {
    return new GenericArrayTypeImpl(cls.getComponentType());
   }
  }
  return type;
 }
},
origin: spring-projects/spring-framework

private Collection<?> convertDataArrayToTargetCollection(Object[] array, Class<?> collectionType, Class<?> elementType)
    throws NoSuchMethodException {
  Method fromMethod = elementType.getMethod("from", array.getClass().getComponentType());
  Collection<Object> resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array));
  for (int i = 0; i < array.length; i++) {
    resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
  }
  return resultColl;
}
origin: spring-projects/spring-framework

/**
 * Check if the given class represents an array of primitive wrappers,
 * i.e. Boolean, Byte, Character, Short, Integer, Long, Float, or Double.
 * @param clazz the class to check
 * @return whether the given class is a primitive wrapper array class
 */
public static boolean isPrimitiveWrapperArray(Class<?> clazz) {
  Assert.notNull(clazz, "Class must not be null");
  return (clazz.isArray() && isPrimitiveWrapper(clazz.getComponentType()));
}
origin: spring-projects/spring-framework

  private void appendType(StringBuilder sb, Class<?> type, boolean useLongTypeName) {
    if (type.isArray()) {
      appendType(sb, type.getComponentType(), useLongTypeName);
      sb.append("[]");
    }
    else {
      sb.append(useLongTypeName ? type.getName() : type.getSimpleName());
    }
  }
}
origin: apache/incubator-dubbo

@Override
public void arrayBegin() throws ParseException {
  mStack.push(mType);
  if (mType.isArray()) {
    mType = mType.getComponentType();
  } else if (mType == Object.class || Collection.class.isAssignableFrom(mType)) {
    mType = Object.class;
  } else {
    throw new ParseException("Convert error, can not load json array data into class [" + mType.getName() + "].");
  }
}
origin: apache/incubator-dubbo

@Override
public void arrayBegin() throws ParseException {
  mStack.push(mType);
  if (mType.isArray()) {
    mType = mType.getComponentType();
  } else if (mType == Object.class || Collection.class.isAssignableFrom(mType)) {
    mType = Object.class;
  } else {
    throw new ParseException("Convert error, can not load json array data into class [" + mType.getName() + "].");
  }
}
origin: apache/incubator-dubbo

private static boolean isPrimitives(Class<?> cls) {
  if (cls.isArray()) {
    return isPrimitive(cls.getComponentType());
  }
  return isPrimitive(cls);
}
origin: apache/incubator-dubbo

@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
  // Process the component type of an array.
  Class<?> componentType = clazz.getComponentType();
  TypeDefinitionBuilder.build(componentType, componentType, typeCache);
  final String canonicalName = clazz.getCanonicalName();
  return new TypeDefinition(canonicalName);
}
origin: apache/incubator-dubbo

@Override
public TypeDefinition build(Type type, Class<?> clazz, Map<Class<?>, TypeDefinition> typeCache) {
  // Process the component type of an array.
  Class<?> componentType = clazz.getComponentType();
  TypeDefinitionBuilder.build(componentType, componentType, typeCache);
  final String canonicalName = clazz.getCanonicalName();
  return new TypeDefinition(canonicalName);
}
origin: apache/incubator-dubbo

private static boolean isPrimitives(Class<?> cls) {
  if (cls.isArray()) {
    return isPrimitive(cls.getComponentType());
  }
  return isPrimitive(cls);
}
origin: apache/incubator-dubbo

public static boolean isPrimitives(Class<?> cls) {
  if (cls.isArray()) {
    return isPrimitive(cls.getComponentType());
  }
  return isPrimitive(cls);
}
origin: apache/incubator-dubbo

public static boolean isPrimitives(Class<?> cls) {
  if (cls.isArray()) {
    return isPrimitive(cls.getComponentType());
  }
  return isPrimitive(cls);
}
origin: google/guava

private TypeToken<? extends T> getArraySubtype(Class<?> subclass) {
 // array is covariant. component type is subtype, so is the array type.
 TypeToken<?> componentSubtype = getComponentType().getSubtype(subclass.getComponentType());
 @SuppressWarnings("unchecked") // component type is subtype, so is array type.
 TypeToken<? extends T> result =
   (TypeToken<? extends T>)
     // If we are passed with int[].class, don't turn it to GenericArrayType
     of(newArrayClassOrGenericArrayType(componentSubtype.runtimeType));
 return result;
}
origin: spring-projects/spring-framework

@Test
public void testBeanPropertyIsArray() {
  PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(ContainerBean.class);
  for (PropertyDescriptor descriptor : descriptors) {
    if ("containedBeans".equals(descriptor.getName())) {
      assertTrue("Property should be an array", descriptor.getPropertyType().isArray());
      assertEquals(descriptor.getPropertyType().getComponentType(), ContainedBean.class);
    }
  }
}
origin: spring-projects/spring-framework

@Test
public void getComponentTypeForClassArray() throws Exception {
  Field field = Fields.class.getField("arrayClassType");
  ResolvableType type = ResolvableType.forField(field);
  assertThat(type.isArray(), equalTo(true));
  assertThat(type.getComponentType().getType(),
      equalTo((Type) ((Class) field.getGenericType()).getComponentType()));
}
origin: spring-projects/spring-framework

@Test
public void testSetupArguments() {
  Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(
      new Class<?>[] {String[].class}, "a", "b", "c");
  assertEquals(1, newArray.length);
  Object firstParam = newArray[0];
  assertEquals(String.class,firstParam.getClass().getComponentType());
  Object[] firstParamArray = (Object[]) firstParam;
  assertEquals(3,firstParamArray.length);
  assertEquals("a",firstParamArray[0]);
  assertEquals("b",firstParamArray[1]);
  assertEquals("c",firstParamArray[2]);
}
java.langClassgetComponentType

Javadoc

Returns a Class object which represents the component type if this class represents an array type. Returns null if this class does not represent an array type. The component type of an array type is the type of the elements of the array.

Popular methods of Class

  • getName
    Returns the name of the class represented by this Class. For a description of the format which is us
  • getSimpleName
  • getClassLoader
  • isAssignableFrom
    Determines if the class or interface represented by this Class object is either the same as, or is a
  • forName
    Returns the Class object associated with the class or interface with the given string name, using th
  • newInstance
    Returns a new instance of the class represented by this Class, created by invoking the default (that
  • getMethod
    Returns a Method object that reflects the specified public member method of the class or interface r
  • getResourceAsStream
    Finds a resource with a given name. The rules for searching resources associated with a given class
  • getSuperclass
    Returns the Class representing the superclass of the entity (class, interface, primitive type or voi
  • getConstructor
  • cast
    Casts an object to the class or interface represented by this Class object.
  • isInstance
  • cast,
  • isInstance,
  • getCanonicalName,
  • getDeclaredField,
  • isArray,
  • getAnnotation,
  • getDeclaredFields,
  • getResource,
  • getDeclaredMethod,
  • getMethods

Popular in Java

  • Making http post requests using okhttp
  • scheduleAtFixedRate (Timer)
  • notifyDataSetChanged (ArrayAdapter)
  • getSharedPreferences (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Socket (java.net)
    Provides a client-side TCP socket.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • JFileChooser (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • 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