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

How to use
getDeclaredField
method
in
java.lang.Class

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

origin: spring-projects/spring-framework

  private void readObject(ObjectInputStream inputStream) throws IOException, ClassNotFoundException {
    inputStream.defaultReadObject();
    try {
      this.field = this.declaringClass.getDeclaredField(this.fieldName);
    }
    catch (Throwable ex) {
      throw new IllegalStateException("Could not find original class structure", ex);
    }
  }
}
origin: google/guava

static <T> FieldSetter<T> getFieldSetter(final Class<T> clazz, String fieldName) {
 try {
  Field field = clazz.getDeclaredField(fieldName);
  return new FieldSetter<T>(field);
 } catch (NoSuchFieldException e) {
  throw new AssertionError(e); // programmer error
 }
}
origin: spring-projects/spring-framework

private static Map<?, ?> getSerializableFactoryMap() throws Exception {
  Field field = DefaultListableBeanFactory.class.getDeclaredField("serializableFactories");
  field.setAccessible(true);
  return (Map<?, ?>) field.get(DefaultListableBeanFactory.class);
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
public Map<String, String> getMap(Object target) {
  try {
    Field f = target.getClass().getDeclaredField(mapName);
    return (Map<String, String>) f.get(target);
  }
  catch (Exception ex) {
  }
  return null;
}
origin: spring-projects/spring-framework

@SuppressWarnings("unchecked")
private static Map<ClassLoader, WebApplicationContext> getCurrentContextPerThreadFromContextLoader() {
  try {
    Field field = ContextLoader.class.getDeclaredField("currentContextPerThread");
    field.setAccessible(true);
    return (Map<ClassLoader, WebApplicationContext>) field.get(null);
  }
  catch (Exception ex) {
    throw new IllegalStateException(ex);
  }
}
origin: google/guava

private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName)
  throws Exception {
 // Make sure we are actually running with the expected helper implementation
 Class<?> abstractFutureClass = classLoader.loadClass(AbstractFuture.class.getName());
 Field helperField = abstractFutureClass.getDeclaredField("ATOMIC_HELPER");
 helperField.setAccessible(true);
 assertEquals(expectedHelperClassName, helperField.get(null).getClass().getSimpleName());
}
origin: google/guava

private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName)
  throws Exception {
 // Make sure we are actually running with the expected helper implementation
 Class<?> abstractFutureClass = classLoader.loadClass(AggregateFutureState.class.getName());
 Field helperField = abstractFutureClass.getDeclaredField("ATOMIC_HELPER");
 helperField.setAccessible(true);
 assertEquals(expectedHelperClassName, helperField.get(null).getClass().getSimpleName());
}
origin: google/guava

@GwtIncompatible // reflection
private static int bucketsOf(HashMap<?, ?> hashMap) throws Exception {
 Field tableField = HashMap.class.getDeclaredField("table");
 tableField.setAccessible(true);
 Object[] table = (Object[]) tableField.get(hashMap);
 // In JDK8, table is set lazily, so it may be null.
 return table == null ? 0 : table.length;
}
origin: spring-projects/spring-framework

private void assertIsCompiled(Expression expression) {
  try {
    Field field = SpelExpression.class.getDeclaredField("compiledAst");
    field.setAccessible(true);
    Object object = field.get(expression);
    assertNotNull(object);
  }
  catch (Exception ex) {
    fail(ex.toString());
  }
}
origin: spring-projects/spring-framework

@Before
public void setUp() throws Exception {
  ExpressionWithConversionTests.typeDescriptorForListOfString = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfString"));
  ExpressionWithConversionTests.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionWithConversionTests.class.getDeclaredField("listOfInteger"));
}
origin: spring-projects/spring-framework

@Test
public void defaultRefreshCheckDelay() throws Exception {
  ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
  Advised advised = (Advised) context.getBean("testBean");
  AbstractRefreshableTargetSource targetSource =
      ((AbstractRefreshableTargetSource) advised.getTargetSource());
  Field field = AbstractRefreshableTargetSource.class.getDeclaredField("refreshCheckDelay");
  field.setAccessible(true);
  long delay = ((Long) field.get(targetSource)).longValue();
  assertEquals(5000L, delay);
}
origin: google/guava

static Element field(String name) throws Exception {
 Element element = new Element(A.class.getDeclaredField(name));
 assertEquals(name, element.getName());
 assertEquals(A.class, element.getDeclaringClass());
 return element;
}
origin: spring-projects/spring-framework

@Test
public void convertArrayToCollectionGenericTypeConversion() throws Exception {
  @SuppressWarnings("unchecked")
  List<Integer> result = (List<Integer>) conversionService.convert(new String[] {"1", "2", "3"}, TypeDescriptor
      .valueOf(String[].class), new TypeDescriptor(getClass().getDeclaredField("genericList")));
  assertEquals(Integer.valueOf(1), result.get(0));
  assertEquals(Integer.valueOf(2), result.get(1));
  assertEquals(Integer.valueOf(3), result.get(2));
}
origin: google/guava

public void testWildcardCaptured_field_upperBound() throws Exception {
 TypeToken<Holder<?>> type = new TypeToken<Holder<?>>() {};
 TypeToken<?> matrixType =
   type.resolveType(Holder.class.getDeclaredField("matrix").getGenericType());
 assertEquals(List[].class, matrixType.getRawType());
 assertThat(matrixType.getType()).isNotEqualTo(new TypeToken<List<?>[]>() {}.getType());
}
origin: google/guava

public void testWildcardCaptured_typeVariableDeclaresTypeBound_wildcardHasNoExplicitUpperBound()
  throws Exception {
 TypeToken<Counter<?>> type = new TypeToken<Counter<?>>() {};
 TypeToken<?> fieldType =
   type.resolveType(Counter.class.getDeclaredField("counts").getGenericType());
 Type[] typeArgs = ((ParameterizedType) fieldType.getType()).getActualTypeArguments();
 assertThat(typeArgs).asList().hasSize(1);
 TypeVariable<?> captured = (TypeVariable<?>) typeArgs[0];
 assertThat(captured.getBounds()).asList().containsExactly(Number.class);
 assertThat(new TypeToken<List<? extends Number>>() {}.isSupertypeOf(fieldType)).isTrue();
 assertThat(new TypeToken<List<? extends Iterable<?>>>() {}.isSupertypeOf(fieldType)).isFalse();
}
origin: google/guava

public void testWildcardCaptured_typeVariableDeclaresTypeBound_wildcardHasExplicitUpperBound()
  throws Exception {
 TypeToken<Counter<? extends Number>> type = new TypeToken<Counter<? extends Number>>() {};
 TypeToken<?> fieldType =
   type.resolveType(Counter.class.getDeclaredField("counts").getGenericType());
 Type[] typeArgs = ((ParameterizedType) fieldType.getType()).getActualTypeArguments();
 assertThat(typeArgs).asList().hasSize(1);
 TypeVariable<?> captured = (TypeVariable<?>) typeArgs[0];
 assertThat(captured.getBounds()).asList().containsExactly(Number.class);
 assertThat(new TypeToken<List<? extends Number>>() {}.isSupertypeOf(fieldType)).isTrue();
 assertThat(new TypeToken<List<? extends Iterable<?>>>() {}.isSupertypeOf(fieldType)).isFalse();
}
origin: spring-projects/spring-framework

@Test
public void fieldList() throws Exception {
  TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("listOfString"));
  assertFalse(typeDescriptor.isArray());
  assertEquals(List.class, typeDescriptor.getType());
  assertEquals(String.class, typeDescriptor.getElementTypeDescriptor().getType());
  assertEquals("java.util.List<java.lang.String>", typeDescriptor.toString());
}
origin: spring-projects/spring-framework

@Test
public void fieldComplexTypeDescriptor() throws Exception {
  TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("arrayOfListOfString"));
  assertTrue(typeDescriptor.isArray());
  assertEquals(List.class,typeDescriptor.getElementTypeDescriptor().getType());
  assertEquals(String.class, typeDescriptor.getElementTypeDescriptor().getElementTypeDescriptor().getType());
  assertEquals("java.util.List<java.lang.String>[]",typeDescriptor.toString());
}
origin: spring-projects/spring-framework

@Test
public void fieldListOfListOfString() throws Exception {
  TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("listOfListOfString"));
  assertFalse(typeDescriptor.isArray());
  assertEquals(List.class, typeDescriptor.getType());
  assertEquals(List.class, typeDescriptor.getElementTypeDescriptor().getType());
  assertEquals(String.class, typeDescriptor.getElementTypeDescriptor().getElementTypeDescriptor().getType());
  assertEquals("java.util.List<java.util.List<java.lang.String>>", typeDescriptor.toString());
}
origin: spring-projects/spring-framework

@Test
public void fieldComplexTypeDescriptor2() throws Exception {
  TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("nestedMapField"));
  assertTrue(typeDescriptor.isMap());
  assertEquals(String.class,typeDescriptor.getMapKeyTypeDescriptor().getType());
  assertEquals(List.class, typeDescriptor.getMapValueTypeDescriptor().getType());
  assertEquals(Integer.class, typeDescriptor.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
  assertEquals("java.util.Map<java.lang.String, java.util.List<java.lang.Integer>>", typeDescriptor.toString());
}
java.langClassgetDeclaredField

Javadoc

Returns a Field object for the field with the given name which is declared in the class represented by this Class.

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,
  • 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)
  • 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