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

How to use
isInstance
method
in
java.lang.Class

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

origin: ReactiveX/RxJava

  @Override
  public boolean test(T t) throws Exception {
    return clazz.isInstance(t);
  }
}
origin: square/retrofit

/** Returns true if {@code annotations} contains an instance of {@code cls}. */
static boolean isAnnotationPresent(Annotation[] annotations,
  Class<? extends Annotation> cls) {
 for (Annotation annotation : annotations) {
  if (cls.isInstance(annotation)) {
   return true;
  }
 }
 return false;
}
origin: iluwatar/java-design-patterns

 private synchronized Heavy createAndCacheHeavy() {
  class HeavyFactory implements Supplier<Heavy> {
   private final Heavy heavyInstance = new Heavy();

   @Override
   public Heavy get() {
    return heavyInstance;
   }
  }
  if (!HeavyFactory.class.isInstance(heavy)) {
   heavy = new HeavyFactory();
  }
  return heavy.get();
 }
}
origin: spring-projects/spring-framework

@Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException {
  if (iface.isInstance(this)) {
    return (T) this;
  }
  throw new SQLException("DataSource of type [" + getClass().getName() +
      "] cannot be unwrapped as [" + iface.getName() + "]");
}
origin: google/guava

 private static boolean isProxyOfSameInterfaces(Object arg, Class<?> proxyClass) {
  return proxyClass.isInstance(arg)
    // Equal proxy instances should mostly be instance of proxyClass
    // Under some edge cases (such as the proxy of JDK types serialized and then deserialized)
    // the proxy type may not be the same.
    // We first check isProxyClass() so that the common case of comparing with non-proxy objects
    // is efficient.
    || (Proxy.isProxyClass(arg.getClass())
      && Arrays.equals(arg.getClass().getInterfaces(), proxyClass.getInterfaces()));
 }
}
origin: spring-projects/spring-framework

@Override
public void registerResolvableDependency(Class<?> dependencyType, @Nullable Object autowiredValue) {
  Assert.notNull(dependencyType, "Dependency type must not be null");
  if (autowiredValue != null) {
    if (!(autowiredValue instanceof ObjectFactory || dependencyType.isInstance(autowiredValue))) {
      throw new IllegalArgumentException("Value [" + autowiredValue +
          "] does not implement specified dependency type [" + dependencyType.getName() + "]");
    }
    this.resolvableDependencies.put(dependencyType, autowiredValue);
  }
}
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

  @Nullable
  public static Object resolvePushBuilder(HttpServletRequest request, Class<?> paramType) {
    PushBuilder pushBuilder = request.newPushBuilder();
    if (pushBuilder != null && !paramType.isInstance(pushBuilder)) {
      throw new IllegalStateException(
          "Current push builder is not of type [" + paramType.getName() + "]: " + pushBuilder);
    }
    return pushBuilder;
  }
}
origin: spring-projects/spring-framework

@Override
@SuppressWarnings("unchecked")
public <T> T getBean(String name, @Nullable Class<T> requiredType) throws BeansException {
  Object bean = getBean(name);
  if (requiredType != null && !requiredType.isInstance(bean)) {
    throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
  }
  return (T) bean;
}
origin: ReactiveX/RxJava

public CrashDummy assertError(Class<? extends Throwable> clazz) {
  if (!clazz.isInstance(error)) {
    throw new AssertionError("Different error: " + error);
  }
  return this;
}
origin: ReactiveX/RxJava

public CrashDummy assertError(Class<? extends Throwable> clazz) {
  if (!clazz.isInstance(error)) {
    throw new AssertionError("Different error: " + error);
  }
  return this;
}
origin: spring-projects/spring-framework

@Override
@SuppressWarnings("unchecked")
public <T> T getNativeRequest(@Nullable Class<T> requiredType) {
  if (requiredType != null) {
    Object request = getExternalContext().getRequest();
    if (requiredType.isInstance(request)) {
      return (T) request;
    }
  }
  return null;
}
origin: ReactiveX/RxJava

public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz) {
  Throwable ex = list.get(index);
  if (!clazz.isInstance(ex)) {
    AssertionError err = new AssertionError(clazz + " expected but got " + list.get(index));
    err.initCause(list.get(index));
    throw err;
  }
}
origin: ReactiveX/RxJava

public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz, String message) {
  Throwable ex = list.get(index);
  if (!clazz.isInstance(ex)) {
    AssertionError err = new AssertionError("Type " + clazz + " expected but got " + ex);
    err.initCause(ex);
    throw err;
  }
  if (!ObjectHelper.equals(message, ex.getMessage())) {
    AssertionError err = new AssertionError("Message " + message + " expected but got " + ex.getMessage());
    err.initCause(ex);
    throw err;
  }
}
origin: google/guava

@Override
public boolean equals(@Nullable Object obj) {
 // In general getClass().isInstance() is bad for equals.
 // But here we fully control the subclasses to ensure symmetry.
 if (getClass().isInstance(obj)) {
  Wrapper that = (Wrapper) obj;
  return wrapped.equals(that.wrapped);
 }
 return false;
}
origin: ReactiveX/RxJava

public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz) {
  Throwable ex = ts.errors().get(0);
  if (ex instanceof CompositeException) {
    CompositeException ce = (CompositeException) ex;
    List<Throwable> cel = ce.getExceptions();
    assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}
origin: ReactiveX/RxJava

public static void assertError(TestObserver<?> to, int index, Class<? extends Throwable> clazz, String message) {
  Throwable ex = to.errors().get(0);
  if (ex instanceof CompositeException) {
    CompositeException ce = (CompositeException) ex;
    List<Throwable> cel = ce.getExceptions();
    assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
    assertEquals(message, cel.get(index).getMessage());
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}
origin: ReactiveX/RxJava

public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz, String message) {
  Throwable ex = ts.errors().get(0);
  if (ex instanceof CompositeException) {
    CompositeException ce = (CompositeException) ex;
    List<Throwable> cel = ce.getExceptions();
    assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
    assertEquals(message, cel.get(index).getMessage());
  } else {
    fail(ex.toString() + ": not a CompositeException");
  }
}
origin: google/guava

 public final void run() {
  try {
   realRun();
   threadShouldThrow(exceptionClass.getSimpleName());
  } catch (Throwable t) {
   if (!exceptionClass.isInstance(t)) threadUnexpectedException(t);
  }
 }
}
origin: google/guava

 public final void run() {
  try {
   realRun();
   threadShouldThrow(exceptionClass.getSimpleName());
  } catch (Throwable t) {
   if (!exceptionClass.isInstance(t)) threadUnexpectedException(t);
  }
 }
}
java.langClassisInstance

Javadoc

Tests whether the given object can be cast to the class represented by this Class. This is the runtime version of the instanceof operator.

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
  • cast
    Casts an object to the class or interface represented by this Class object.
  • getCanonicalName
    Returns the canonical name of the underlying class as defined by the Java Language Specification. Re
  • cast,
  • 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 PhpStorm 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