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

How to use
getField
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.getField (Showing top 20 results out of 42,498)

origin: spring-projects/spring-framework

protected ResolvableType getGenericApplicationEventType(String fieldName) {
  try {
    return ResolvableType.forField(TestEvents.class.getField(fieldName));
  }
  catch (NoSuchFieldException ex) {
    throw new IllegalStateException("No such field on Events '" + fieldName + "'");
  }
}
origin: spring-projects/spring-framework

@Test
public void isAssignableMapKeyValueTypes() throws Exception {
  assertTrue(new TypeDescriptor(getClass().getField("mapField")).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
  assertTrue(new TypeDescriptor(getClass().getField("notGenericMap")).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
  assertTrue(new TypeDescriptor(getClass().getField("mapField")).isAssignableTo(new TypeDescriptor(getClass().getField("notGenericMap"))));
  assertFalse(new TypeDescriptor(getClass().getField("isAssignableMapKeyValueTypes")).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
  assertTrue(TypeDescriptor.valueOf(Map.class).isAssignableTo(new TypeDescriptor(getClass().getField("mapField"))));
}
origin: google/guava

public void testInnerClassWithParameterizedOwner() throws Exception {
 Type fieldType = ParameterizedOuter.class.getField("field").getGenericType();
 assertEquals(
   fieldType, TypeToken.of(ParameterizedOuter.class).resolveType(fieldType).getType());
}
origin: spring-projects/spring-framework

@Test
public void convertMapToMap() throws Exception {
  Map<String, String> foo = new HashMap<>();
  foo.put("1", "BAR");
  foo.put("2", "BAZ");
  @SuppressWarnings("unchecked")
  Map<Integer, FooEnum> map = (Map<Integer, FooEnum>) conversionService.convert(foo,
      TypeDescriptor.forObject(foo), new TypeDescriptor(getClass().getField("genericMap")));
  assertEquals(FooEnum.BAR, map.get(1));
  assertEquals(FooEnum.BAZ, map.get(2));
}
origin: spring-projects/spring-framework

@Test
public void wildcardType() throws Exception {
  ParameterizedType typeSource = (ParameterizedType) SerializableTypeWrapper.forField(Fields.class.getField("wildcardType"));
  WildcardType type = (WildcardType) typeSource.getActualTypeArguments()[0];
  assertThat(type.toString(), equalTo("? extends java.lang.CharSequence"));
  assertSerializable(type);
  assertSerializable(type.getLowerBounds());
  assertSerializable(type.getUpperBounds());
}
origin: spring-projects/spring-framework

@Test
public void testWildcardMap() throws Exception {
  Map<String, String> input = new LinkedHashMap<>();
  input.put("key", "value");
  Object converted = conversionService.convert(input, TypeDescriptor.forObject(input), new TypeDescriptor(getClass().getField("wildcardMap")));
  assertEquals(input, converted);
}
origin: spring-projects/spring-framework

@Test
public void paramaterizedType() throws Exception {
  ResolvableType type = ResolvableType.forField(Fields.class.getField("parameterizedType"));
  assertThat(type.getType(), instanceOf(ParameterizedType.class));
}
origin: spring-projects/spring-framework

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

@Test
public void resolveArrayClassType() throws Exception {
  ResolvableType type = ResolvableType.forField(Fields.class.getField("arrayClassType"));
  assertThat(type.resolve(), equalTo((Class) List[].class));
}
origin: spring-projects/spring-framework

@Test
public void testStringToEnumSet() throws Exception {
  assertEquals(EnumSet.of(Foo.BAR), conversionService.convert("BAR", TypeDescriptor.valueOf(String.class),
      new TypeDescriptor(getClass().getField("enumSet"))));
}
origin: spring-projects/spring-framework

@Test
public void getGenericOfGenericByIndexes() throws Exception {
  ResolvableType type = ResolvableType.forField(Fields.class.getField("stringListList"));
  assertThat(type.getGeneric(0, 0).getType(), equalTo((Type) String.class));
}
origin: spring-projects/spring-framework

@Test
public void resolveWildcardLowerBounds() throws Exception {
  ResolvableType type = ResolvableType.forField(Fields.class.getField("wildcardSuperType"));
  assertThat(type.getGeneric().resolve(), equalTo((Class) Number.class));
}
origin: spring-projects/spring-framework

@Test
public void emptyMapDifferentTargetImplType() throws Exception {
  Map<String, String> map = new HashMap<>();
  TypeDescriptor sourceType = TypeDescriptor.forObject(map);
  TypeDescriptor targetType = new TypeDescriptor(getClass().getField("emptyMapDifferentTarget"));
  assertTrue(conversionService.canConvert(sourceType, targetType));
  @SuppressWarnings("unchecked")
  LinkedHashMap<String, String> result = (LinkedHashMap<String, String>) conversionService.convert(map, sourceType, targetType);
  assertEquals(map, result);
  assertEquals(LinkedHashMap.class, result.getClass());
}
origin: spring-projects/spring-framework

@Test
public void wildcardType() throws Exception {
  ResolvableType type = ResolvableType.forField(Fields.class.getField("wildcardType"));
  assertThat(type.getType(), instanceOf(ParameterizedType.class));
  assertThat(type.getGeneric().getType(), instanceOf(WildcardType.class));
}
origin: spring-projects/spring-framework

@Test
public void getGenericByIndex() throws Exception {
  ResolvableType type = ResolvableType.forField(Fields.class.getField("stringIntegerMultiValueMap"));
  assertThat(type.getGeneric(0).getType(), equalTo((Type) String.class));
  assertThat(type.getGeneric(1).getType(), equalTo((Type) Integer.class));
}
origin: spring-projects/spring-framework

@Test
public void serialize() throws Exception {
  testSerialization(ResolvableType.forClass(List.class));
  testSerialization(ResolvableType.forField(Fields.class.getField("charSequenceList")));
  testSerialization(ResolvableType.forMethodParameter(Methods.class.getMethod("charSequenceParameter", List.class), 0));
  testSerialization(ResolvableType.forMethodReturnType(Methods.class.getMethod("charSequenceReturn")));
  testSerialization(ResolvableType.forConstructorParameter(Constructors.class.getConstructor(List.class), 0));
  testSerialization(ResolvableType.forField(Fields.class.getField("charSequenceList")).getGeneric());
  ResolvableType deserializedNone = testSerialization(ResolvableType.NONE);
  assertThat(deserializedNone, sameInstance(ResolvableType.NONE));
}
origin: spring-projects/spring-framework

@Test
public void elementTypePreserveContext() throws Exception {
  TypeDescriptor desc = new TypeDescriptor(getClass().getField("listPreserveContext"));
  assertEquals(Integer.class, desc.getElementTypeDescriptor().getElementTypeDescriptor().getType());
  List<Integer> value = new ArrayList<>(3);
  desc = desc.elementTypeDescriptor(value);
  assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
  assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}
origin: spring-projects/spring-framework

@Test
public void testSpr11219() throws Exception {
  ResolvableType type = ResolvableType.forField(BaseProvider.class.getField("stuff"), BaseProvider.class);
  assertTrue(type.getNested(2).isAssignableFrom(ResolvableType.forClass(BaseImplementation.class)));
  assertEquals("java.util.Collection<org.springframework.core.ResolvableTypeTests$IBase<?>>", type.toString());
}
origin: spring-projects/spring-framework

@Test
public void fieldScalar() throws Exception {
  TypeDescriptor typeDescriptor = new TypeDescriptor(getClass().getField("fieldScalar"));
  assertFalse(typeDescriptor.isPrimitive());
  assertFalse(typeDescriptor.isArray());
  assertFalse(typeDescriptor.isCollection());
  assertFalse(typeDescriptor.isMap());
  assertEquals(Integer.class, typeDescriptor.getType());
  assertEquals(Integer.class, typeDescriptor.getObjectType());
}
origin: spring-projects/spring-framework

@Test
public void fieldMap() throws Exception {
  TypeDescriptor desc = new TypeDescriptor(TypeDescriptorTests.class.getField("fieldMap"));
  assertTrue(desc.isMap());
  assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType());
  assertEquals(Long.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
}
java.langClassgetField

Javadoc

Returns a Field object which represents the public field with the given name. This method first searches the class C represented by this Class, then the interfaces implemented by C and finally the superclasses of C.

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

  • Parsing JSON documents to java classes using gson
  • setRequestProperty (URLConnection)
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Collectors (java.util.stream)
  • Top Vim plugins
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