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

How to use
cast
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.cast (Showing top 20 results out of 45,828)

origin: ReactiveX/RxJava

  @Override
  public U apply(T t) throws Exception {
    return clazz.cast(t);
  }
}
origin: google/guava

static void checkCast(Class<?> clazz, Object obj) {
 clazz.cast(obj);
}
origin: greenrobot/EventBus

/**
 * Gets the most recent sticky event for the given type.
 *
 * @see #postSticky(Object)
 */
public <T> T getStickyEvent(Class<T> eventType) {
  synchronized (stickyEvents) {
    return eventType.cast(stickyEvents.get(eventType));
  }
}
origin: greenrobot/EventBus

/**
 * Remove and gets the recent sticky event for the given event type.
 *
 * @see #postSticky(Object)
 */
public <T> T removeStickyEvent(Class<T> eventType) {
  synchronized (stickyEvents) {
    return eventType.cast(stickyEvents.remove(eventType));
  }
}
origin: google/guava

private static <T> T newProxy(Class<T> interfaceType, InvocationHandler handler) {
 Object object =
   Proxy.newProxyInstance(
     interfaceType.getClassLoader(), new Class<?>[] {interfaceType}, handler);
 return interfaceType.cast(object);
}
origin: square/okhttp

/**
 * Returns the tag attached with {@code type} as a key, or null if no tag is attached with that
 * key.
 */
public @Nullable <T> T tag(Class<? extends T> type) {
 return type.cast(tags.get(type));
}
origin: google/guava

private static <T> T expectArgument(Class<T> type, Object arg) {
 try {
  return type.cast(arg);
 } catch (ClassCastException e) {
  throw new IllegalArgumentException(arg + " is not a " + type.getSimpleName());
 }
}
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 static List<TypeElement> staticTypesIn(Iterable<? extends Element> elements) {
  List<TypeElement> list = new ArrayList<>();
  for (Element element : elements) {
    if (TYPE_KINDS.contains(element.getKind()) && element.getModifiers().contains(Modifier.STATIC)) {
      list.add(TypeElement.class.cast(element));
    }
  }
  return list;
}
origin: google/guava

@Override
public <A extends Annotation> @Nullable A getAnnotation(Class<A> annotationType) {
 checkNotNull(annotationType);
 for (Annotation annotation : annotations) {
  if (annotationType.isInstance(annotation)) {
   return annotationType.cast(annotation);
  }
 }
 return null;
}
origin: spring-projects/spring-framework

  @Override
  protected <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException {
    ++this.callCount;
    return requiredType.cast(DESTINATION);
  }
}
origin: google/guava

static <T extends Enum<T>> Optional<T> getEnumIfPresent(Class<T> enumClass, String value) {
 WeakReference<? extends Enum<?>> ref = Enums.getEnumConstants(enumClass).get(value);
 return ref == null ? Optional.<T>absent() : Optional.of(enumClass.cast(ref.get()));
}
origin: google/guava

 @Override
 public sun.misc.Unsafe run() throws Exception {
  Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
  for (java.lang.reflect.Field f : k.getDeclaredFields()) {
   f.setAccessible(true);
   Object x = f.get(null);
   if (k.isInstance(x)) {
    return k.cast(x);
   }
  }
  throw new NoSuchFieldError("the Unsafe");
 }
});
origin: google/guava

private static <B, T extends B> T cast(Class<T> type, B value) {
 return Primitives.wrap(type).cast(value);
}
origin: google/guava

@CanIgnoreReturnValue
private static <B, T extends B> T cast(Class<T> type, B value) {
 return Primitives.wrap(type).cast(value);
}
origin: google/guava

@Nullable
final <T> T generateFresh(Class<T> type) {
 return Primitives.wrap(type).cast(generateFresh(TypeToken.of(type)));
}
origin: spring-projects/spring-framework

  @Override
  protected <T> T lookup(String jndiName, Class<T> requiredType) {
    assertEquals(DATA_SOURCE_NAME, jndiName);
    return requiredType.cast(expectedDataSource);
  }
};
origin: spring-projects/spring-framework

  @Override
  protected <T> T lookup(String jndiName, Class<T> requiredType) throws NamingException {
    if (called) {
      fail("Must not be delegating to lookup(..), must be resolving from cache.");
    }
    assertEquals(DESTINATION_NAME, jndiName);
    called = true;
    return requiredType.cast(DESTINATION);
  }
}
origin: spring-projects/spring-framework

protected <T extends JCacheOperation<?>> T getCacheOperation(
    Class<T> operationType, Class<?> targetType, String methodName, Class<?>... parameterTypes) {
  JCacheOperation<?> result = getCacheOperation(targetType, methodName, parameterTypes);
  assertNotNull(result);
  assertEquals(operationType, result.getClass());
  return operationType.cast(result);
}
origin: spring-projects/spring-framework

protected TextMessage createTextMessage(MessageCreator creator) throws JMSException {
  Session mock = mock(Session.class);
  given(mock.createTextMessage(BDDMockito.any())).willAnswer(
      (Answer<TextMessage>) invocation ->
          new StubTextMessage((String) invocation.getArguments()[0]));
  javax.jms.Message message = creator.createMessage(mock);
  verify(mock).createTextMessage(BDDMockito.any());
  return TextMessage.class.cast(message);
}
java.langClasscast

Javadoc

Casts the given object to the type represented by this Class. If the object is null then the result is also null.

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
  • getSuperclass
    Returns the Class representing the superclass of the entity (class, interface, primitive type or voi
  • getConstructor
  • isInstance
  • getCanonicalName
    Returns the canonical name of the underlying class as defined by the Java Language Specification. Re
  • 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
  • Top plugins for WebStorm
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