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

How to use
asSubclass
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.asSubclass (Showing top 20 results out of 11,025)

origin: spring-projects/spring-framework

/**
 * Cast the given type to a subtype of {@link Enum}.
 * @param enumType the enum type, never {@code null}
 * @return the given type as subtype of {@link Enum}
 * @throws IllegalArgumentException if the given type is not a subtype of {@link Enum}
 */
@SuppressWarnings("rawtypes")
private static Class<? extends Enum> asEnumType(Class<?> enumType) {
  Assert.notNull(enumType, "Enum type must not be null");
  if (!Enum.class.isAssignableFrom(enumType)) {
    throw new IllegalArgumentException("Supplied type is not an enum: " + enumType.getName());
  }
  return enumType.asSubclass(Enum.class);
}
origin: junit-team/junit4

public JUnit38ClassRunner(Class<?> klass) {
  this(new TestSuite(klass.asSubclass(TestCase.class)));
}
origin: google/guava

 @Override
 protected Boolean computeValue(Class<?> type) {
  checkExceptionClassValidity(type.asSubclass(Exception.class));
  return true;
 }
};
origin: apache/kafka

/**
 * Look up a class by name.
 * @param klass class name
 * @param base super class of the class for verification
 * @param <T> the type of the base class
 * @return the new class
 */
public static <T> Class<? extends T> loadClass(String klass, Class<T> base) throws ClassNotFoundException {
  return Class.forName(klass, true, Utils.getContextOrKafkaClassLoader()).asSubclass(base);
}
origin: prestodb/presto

private static AWSCredentialsProvider getCustomAWSCredentialsProvider(Configuration conf, String providerClass)
{
  try {
    return conf.getClassByName(providerClass)
        .asSubclass(AWSCredentialsProvider.class)
        .getConstructor(URI.class, Configuration.class)
        .newInstance(null, conf);
  }
  catch (ReflectiveOperationException e) {
    throw new RuntimeException(format("Error creating an instance of %s", providerClass), e);
  }
}
origin: prestodb/presto

 @Override
 protected Boolean computeValue(Class<?> type) {
  checkExceptionClassValidity(type.asSubclass(Exception.class));
  return true;
 }
};
origin: prestodb/presto

@SuppressWarnings({"unchecked", "RedundantCast"})
private static Class<? extends InputFormat<?, ?>> getInputFormatClass(JobConf conf, String inputFormatName)
    throws ClassNotFoundException
{
  // CDH uses different names for Parquet
  if ("parquet.hive.DeprecatedParquetInputFormat".equals(inputFormatName) ||
      "parquet.hive.MapredParquetInputFormat".equals(inputFormatName)) {
    return MapredParquetInputFormat.class;
  }
  Class<?> clazz = conf.getClassByName(inputFormatName);
  return (Class<? extends InputFormat<?, ?>>) clazz.asSubclass(InputFormat.class);
}
origin: junit-team/junit4

private Test testCaseForClass(Class<?> each) {
  if (TestCase.class.isAssignableFrom(each)) {
    return new TestSuite(each.asSubclass(TestCase.class));
  } else {
    return warning(each.getCanonicalName() + " does not extend TestCase");
  }
}
origin: google/j2objc

private Test testCaseForClass(Class<?> each) {
  if (TestCase.class.isAssignableFrom(each)) {
    return new TestSuite(each.asSubclass(TestCase.class));
  } else {
    return warning(each.getCanonicalName() + " does not extend TestCase");
  }
}
origin: jenkinsci/jenkins

@Override
public List<? extends ToolInstaller> getDefaultInstallers() {
  try {
    Class<? extends ToolInstaller> jdkInstallerClass = Jenkins.getInstance().getPluginManager()
        .uberClassLoader.loadClass("hudson.tools.JDKInstaller").asSubclass(ToolInstaller.class);
    Constructor<? extends ToolInstaller> constructor = jdkInstallerClass.getConstructor(String.class, boolean.class);
    return Collections.singletonList(constructor.newInstance(null, false));
  } catch (ClassNotFoundException e) {
    return Collections.emptyList();
  } catch (Exception e) {
    LOGGER.log(Level.WARNING, "Unable to get default installer", e);
    return Collections.emptyList();
  }
}
origin: prestodb/presto

private static AWSCredentialsProvider getCustomAWSCredentialsProvider(URI uri, Configuration conf, String providerClass)
{
  try {
    log.debug("Using AWS credential provider %s for URI %s", providerClass, uri);
    return conf.getClassByName(providerClass)
        .asSubclass(AWSCredentialsProvider.class)
        .getConstructor(URI.class, Configuration.class)
        .newInstance(uri, conf);
  }
  catch (ReflectiveOperationException e) {
    throw new RuntimeException(format("Error creating an instance of %s for URI %s", providerClass, uri), e);
  }
}
origin: apache/flink

  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    // read the parent fields and the final fields
    in.defaultReadObject();

    try {
      Class<? extends Writable> writableSplit = splitType.asSubclass(Writable.class);
      mapreduceInputSplit = (org.apache.hadoop.mapreduce.InputSplit) WritableFactories.newInstance(writableSplit);
    }

    catch (Exception e) {
      throw new RuntimeException("Unable to instantiate the Hadoop InputSplit", e);
    }

    ((Writable) mapreduceInputSplit).readFields(in);
  }
}
origin: jenkinsci/jenkins

/**
 * @deprecated Use {@link #getAction(Class)} on {@code AbstractTestResultAction}.
 */
@Deprecated
public Action getTestResultAction() {
  try {
    return getAction(Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass("hudson.tasks.test.AbstractTestResultAction").asSubclass(Action.class));
  } catch (ClassNotFoundException x) {
    return null;
  }
}
origin: jenkinsci/jenkins

/**
 * @deprecated Use {@link #getAction(Class)} on {@code AggregatedTestResultAction}.
 */
@Deprecated
public Action getAggregatedTestResultAction() {
  try {
    return getAction(Jenkins.getInstance().getPluginManager().uberClassLoader.loadClass("hudson.tasks.test.AggregatedTestResultAction").asSubclass(Action.class));
  } catch (ClassNotFoundException x) {
    return null;
  }
}
origin: prestodb/presto

private static <T> T newInstance(String className, Class<T> superType)
    throws ReflectiveOperationException
{
  return HiveStorageFormat.class.getClassLoader().loadClass(className).asSubclass(superType).getConstructor().newInstance();
}
origin: prestodb/presto

private static Constructor<? extends RecordWriter> getOrcWriterConstructor()
{
  try {
    Constructor<? extends RecordWriter> constructor = OrcOutputFormat.class.getClassLoader()
        .loadClass(ORC_RECORD_WRITER)
        .asSubclass(RecordWriter.class)
        .getDeclaredConstructor(Path.class, WriterOptions.class);
    constructor.setAccessible(true);
    return constructor;
  }
  catch (ReflectiveOperationException e) {
    throw new RuntimeException(e);
  }
}
origin: junit-team/junit4

protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception {
  Class<? extends TestCase> testClass = loadSuiteClass(testCase).asSubclass(TestCase.class);
  Test test = TestSuite.createTest(testClass, method);
  return doRun(test, wait);
}
origin: junit-team/junit4

static FilterFactory createFilterFactory(String filterFactoryFqcn) throws FilterNotCreatedException {
  Class<? extends FilterFactory> filterFactoryClass;
  try {
    filterFactoryClass = Classes.getClass(filterFactoryFqcn).asSubclass(FilterFactory.class);
  } catch (Exception e) {
    throw new FilterNotCreatedException(e);
  }
  return createFilterFactory(filterFactoryClass);
}
origin: google/j2objc

protected TestResult runSingleMethod(String testCase, String method, boolean wait) throws Exception {
  Class<? extends TestCase> testClass = loadSuiteClass(testCase).asSubclass(TestCase.class);
  Test test = TestSuite.createTest(testClass, method);
  return doRun(test, wait);
}
origin: jenkinsci/jenkins

  public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    try {
      DescribableList r = (DescribableList) context.getRequiredType().asSubclass(DescribableList.class).newInstance();
      CopyOnWriteList core = copyOnWriteListConverter.unmarshal(reader, context);
      r.data.replaceBy(core);
      return r;
    } catch (InstantiationException e) {
      InstantiationError x = new InstantiationError();
      x.initCause(e);
      throw x;
    } catch (IllegalAccessException e) {
      IllegalAccessError x = new IllegalAccessError();
      x.initCause(e);
      throw x;
    }
  }
}
java.langClassasSubclass

Javadoc

Casts this Class to represent a subclass of the given class. If successful, this Class is returned; otherwise a ClassCastException is thrown.

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