Java Class Exist classExists(String className, Object context)

Here you can find the source of classExists(String className, Object context)

Description

Checks if a certain class name exists in a certain object context's class loader.

License

Open Source License

Parameter

Parameter Description
className a parameter
context a parameter

Declaration

public static boolean classExists(String className, Object context) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w  w  .  j  a v a  2s .co  m
     * Checks if a certain class name exists in a certain object context's class
     * loader.
     * 
     * @param className
     * @param context
     * @return
     */
    public static boolean classExists(String className, Object context) {
        boolean canWork = false;
        try {
            canWork = Class.forName(className, false, context.getClass().getClassLoader()) != null;

        }
        //catch (ClassNotFoundException e)
        //{
        //}
        catch (Exception e) {
            // Normally throws checked ClassNotFoundException
            // This also throws unckecked security exceptions
        }

        return canWork;
    }
}

Related

  1. classExists(ClassLoader loader, String className)
  2. classExists(String className)
  3. classExists(String className)
  4. classExists(String className)
  5. classExists(String implClassName)
  6. classExists(String name)