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

How to use
forName
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.forName (Showing top 20 results out of 105,507)

origin: iluwatar/java-design-patterns

 private static Class<?> getCommandClass(String request) {
  Class<?> result;
  try {
   result = Class.forName("com.iluwatar.front.controller." + request + "Command");
  } catch (ClassNotFoundException e) {
   result = UnknownCommand.class;
  }
  return result;
 }
}
origin: apache/incubator-dubbo

  private Object readResolve() {

    try {
      Class c = Class.forName("java.time.OffsetDateTime");
      Method m = c.getDeclaredMethod("of", Class.forName("java.time.LocalDateTime"),
          Class.forName("java.time.ZoneOffset"));
      return m.invoke(null, dateTime, offset);
    } catch (Throwable t) {
      // ignore
    }
    return null;
  }
}
origin: google/guava

 @Override
 public Class<?> loadFinalizer() {
  try {
   return Class.forName(FINALIZER_CLASS_NAME);
  } catch (ClassNotFoundException e) {
   throw new AssertionError(e);
  }
 }
}
origin: spring-projects/spring-framework

private static boolean isPresent(String className) {
  try {
    Class.forName(className, false, LogAdapter.class.getClassLoader());
    return true;
  }
  catch (ClassNotFoundException ex) {
    return false;
  }
}
origin: apache/incubator-dubbo

  private Object readResolve() {
    try {
      Class c = Class.forName("java.time.Instant");
      Method m = c.getDeclaredMethod("ofEpochSecond", long.class, long.class);
      return m.invoke(null, seconds, nanos);
    } catch (Throwable t) {
      // ignore
    }
    return null;
  }
}
origin: apache/incubator-dubbo

  private Object readResolve() {
    try {
      Class c = Class.forName("java.time.Period");
      Method m = c.getDeclaredMethod("of", int.class, int.class, int.class);
      return m.invoke(null, years, months, days);
    } catch (Throwable t) {
      // ignore
    }
    return null;
  }
}
origin: apache/incubator-dubbo

public YearHandle(Object o) {
  try {
    Class c = Class.forName("java.time.Year");
    Method m = c.getDeclaredMethod("getValue");
    this.year = (Integer) m.invoke(o);
  } catch (Throwable t) {
    // ignore
  }
}
origin: apache/incubator-dubbo

  private Object readResolve() {
    try {
      Class c = Class.forName("java.time.Year");
      Method m = c.getDeclaredMethod("of", int.class);
      return m.invoke(null, year);
    } catch (Throwable t) {
      // ignore
    }
    return null;
  }
}
origin: apache/incubator-dubbo

public InstantHandle(Object o) {
  try {
    Class c = Class.forName("java.time.Instant");
    Method m = c.getDeclaredMethod("getEpochSecond");
    this.seconds = (Long) m.invoke(o);
    m = c.getDeclaredMethod("getNano");
    this.nanos = (Integer) m.invoke(o);
  } catch (Throwable t) {
    // ignore
  }
}
origin: apache/incubator-dubbo

public DurationHandle(Object o) {
  try {
    Class c = Class.forName("java.time.Duration");
    Method m = c.getDeclaredMethod("getSeconds");
    this.seconds = (Long) m.invoke(o);
    m = c.getDeclaredMethod("getNano");
    this.nanos = (Integer) m.invoke(o);
  } catch (Throwable t) {
    // ignore
  }
}
origin: square/okhttp

public CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager trustManager) {
 try {
  Class<?> extensionsClass = Class.forName("android.net.http.X509TrustManagerExtensions");
  Constructor<?> constructor = extensionsClass.getConstructor(X509TrustManager.class);
  Object extensions = constructor.newInstance(trustManager);
  Method checkServerTrusted = extensionsClass.getMethod(
    "checkServerTrusted", X509Certificate[].class, String.class, String.class);
  return new AndroidCertificateChainCleaner(extensions, checkServerTrusted);
 } catch (Exception e) {
  throw new AssertionError(e);
 }
}
origin: bumptech/glide

static ClassName checkResult() {
 try {
  Class.forName(ANDROIDX_CHECK_RESULT_ANNOTATION.reflectionName());
  return ANDROIDX_CHECK_RESULT_ANNOTATION;
 } catch (ClassNotFoundException e) {
  return CHECK_RESULT_ANNOTATION;
 }
}
origin: bumptech/glide

static ClassName nonNull() {
 try {
  Class.forName(ANDROIDX_NONNULL_ANNOTATION.reflectionName());
  return ANDROIDX_NONNULL_ANNOTATION;
 } catch (ClassNotFoundException e) {
  return NONNULL_ANNOTATION;
 }
}
origin: apache/incubator-dubbo

private static boolean isZoneId(Class cl) {
  try {
    return isJava8() && Class.forName("java.time.ZoneId").isAssignableFrom(cl);
  } catch (ClassNotFoundException e) {
    // ignore
  }
  return false;
}
origin: square/okhttp

@Override public boolean isCleartextTrafficPermitted(String hostname) {
 try {
  Class<?> networkPolicyClass = Class.forName("android.security.NetworkSecurityPolicy");
  Method getInstanceMethod = networkPolicyClass.getMethod("getInstance");
  Object networkSecurityPolicy = getInstanceMethod.invoke(null);
  return api24IsCleartextTrafficPermitted(hostname, networkPolicyClass, networkSecurityPolicy);
 } catch (ClassNotFoundException | NoSuchMethodException e) {
  return super.isCleartextTrafficPermitted(hostname);
 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
  throw new AssertionError("unable to determine cleartext support", e);
 }
}
origin: google/guava

private static Method getJdkNextDown() throws Exception {
 try {
  return Math.class.getMethod("nextDown", double.class);
 } catch (NoSuchMethodException expectedBeforeJava8) {
  return Class.forName("sun.misc.FpUtils").getMethod("nextDown", double.class);
 }
}
origin: square/okhttp

public static ConscryptPlatform buildIfSupported() {
 try {
  // Trigger an early exception over a fatal error, prefer a RuntimeException over Error.
  Class.forName("org.conscrypt.Conscrypt");
  if (!Conscrypt.isAvailable()) {
   return null;
  }
  return new ConscryptPlatform();
 } catch (ClassNotFoundException e) {
  return null;
 }
}
origin: spring-projects/spring-framework

  @Bean
  @Lazy
  public Object notLoadable() throws Exception {
    return Class.forName("does.not.exist").newInstance();
  }
}
origin: spring-projects/spring-framework

@Test
public void testCollectionsEmptyList() throws Exception {
  CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService());
  TypeDescriptor type = new TypeDescriptor(getClass().getField("list"));
  converter.convert(list, type, TypeDescriptor.valueOf(Class.forName("java.util.Collections$EmptyList")));
}
origin: google/guava

public void testLexicographicalComparatorChoice() throws Exception {
 Comparator<byte[]> defaultComparator = UnsignedBytes.lexicographicalComparator();
 assertNotNull(defaultComparator);
 assertSame(defaultComparator, UnsignedBytes.lexicographicalComparator());
 if (unsafeComparatorAvailable()) {
  assertSame(defaultComparator.getClass(), Class.forName(unsafeComparatorClassName()));
 } else {
  assertSame(defaultComparator, UnsignedBytes.lexicographicalComparatorJavaImpl());
 }
}
java.langClassforName

Javadoc

Returns a Class object which represents the class with the given name. The name should be the name of a non-primitive class, as described in the Class. Primitive types can not be found using this method; use int.class or Integer.TYPE instead.

If the class has not yet been loaded, it is loaded and initialized first. This is done through either the class loader of the calling class or one of its parent class loaders. It is possible that a static initializer is run as a result of this call.

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

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