Package: java.lang

## [Java] Class Class

- java.lang.Class

-     public class Class
      extends Object

  GDK enhancements for Class.

  displayName:
    Class
  receiverFqcn:
    java.lang.Class

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public URL` | `getLocation()` Gets the url of the jar file/source file containing the specified class.
    `` | `public MetaClass` | `getMetaClass()` Adds a "metaClass" property to all class objects so you can use the syntax `String.metaClass.myMethod = { println "foo" }`
    `` | `public boolean` | `isCase(Object switchValue)` Special 'case' implementation for Class, which allows testing whether some switch value is assignable from the given case class.
    `` | `public boolean` | `isNotCase(Object switchValue)` Since: 4.0.0
    `` | `public MetaClass` | `metaClass(Closure closure)` Sets/updates the metaclass for a given class to a closure.
    `` | `public void` | `mixin(List<Class> categoryClasses)` Extend class globally with category methods.
    `` | `public void` | `mixin(Class categoryClass)` Extend class globally with category methods.
    `` | `public void` | `mixin(Class[] categoryClass)` Extend class globally with category methods.
    `<T>` | `public T` | `newInstance()` Convenience method to dynamically create a new instance of this class.
    `<T>` | `public T` | `newInstance(Object[] args)` Helper to construct a new instance from the given arguments.
    `` | `public void` | `setMetaClass(MetaClass metaClass)` Sets the metaclass for a given class.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `addShutdownHook, any, any, asBoolean, asType, collect, collect, collect, dump, each, eachMatch, eachMatch, eachWithIndex, every, every, find, find, findAll, findAll, findIndexOf, findIndexOf, findIndexValues, findIndexValues, findLastIndexOf, findLastIndexOf, findResult, findResult, findResult, findResult, getAt, getMetaClass, getMetaPropertyValues, getProperties, grep, grep, hasProperty, identity, inject, inject, inspect, invokeMethod, is, isCase, isNotCase, iterator, metaClass, print, print, printf, printf, println, println, println, putAt, respondsTo, respondsTo, setMetaClass, sleep, sleep, split, sprintf, sprintf, stream, tap, toString, use, use, use, with, with, withCloseable, withCloseable, withMethodClosure, withStream, withStream, withTraits`

- - ### Method Detail

    - #### public URL getLocation()

      Gets the url of the jar file/source file containing the specified class.

      Returns:
        the url of the jar, `null` if the specified class is from JDK
      Since:
        2.5.0

    - #### public MetaClass getMetaClass()

      Adds a "metaClass" property to all class objects so you can use the syntax `String.metaClass.myMethod = { println "foo" }`

      Returns:
        An MetaClass instance
      Since:
        1.5.0

    - #### public boolean isCase(Object switchValue)

      Special 'case' implementation for Class, which allows testing whether some switch value is assignable from the given case class. If the switch value is an object, `isCase` will return true if the switch value is assignment compatible with the class (case value), i.e. is an `instanceof` the class, for example:

           def someList = []
           switch (someList) {
             case List:
               assert true : 'is a list'
               break
             case Map:
               assert false : 'is not a Map'
               break
             default:
               assert false : 'should never get here'
               break
           }

      If the switch value is a class, `isCase` will return true if the switch value is assignable from the given class (case value), i.e. the case class is the same as, or a superclass, or a super-interface of the switch class, for example:

           switch (ArrayList) {
             case List:
               assert true : 'is a list'
               break
             case Map:
               assert false : 'is not a Map'
               break
             default:
               assert false : 'should never get here'
               break
           }

      Parameters:
        `switchValue` - the switch value
      Returns:
        true if the switchValue is deemed to be assignable from the given class
      Since:
        1.0

    - #### public boolean isNotCase(Object switchValue)

      Since:
        4.0.0

    - #### public MetaClass metaClass(Closure closure)

      Sets/updates the metaclass for a given class to a closure.

      throws:
        GroovyRuntimeException if the metaclass can't be set for this class
      Parameters:
        `closure` - the closure representing the new metaclass
      Returns:
        the new metaclass value
      Since:
        1.6.0

    - #### public void mixin(List<Class> categoryClasses)

      Extend class globally with category methods. All methods for given class and all super classes will be added to the class.

      Parameters:
        `categoryClasses` - a category classes to use
      Since:
        1.6.0

    - #### public void mixin(Class categoryClass)

      Extend class globally with category methods.

      Parameters:
        `categoryClass` - a category class to use
      Since:
        1.6.0

    - #### public void mixin(Class[] categoryClass)

      Extend class globally with category methods.

      Parameters:
        `categoryClass` - a category class to use
      Since:
        1.6.0

    - #### <T> public T newInstance()

      Convenience method to dynamically create a new instance of this class. Calls the default constructor.

      Returns:
        a new instance of this class
      Since:
        1.0

    - #### <T> public T newInstance(Object[] args)

      Helper to construct a new instance from the given arguments. The constructor is called based on the number and types in the args array. Use `newInstance(null)` or simply `newInstance()` for the default (no-arg) constructor.

      Parameters:
        `args` - the constructor arguments
      Returns:
        a new instance of this class.
      Since:
        1.0

    - #### public void setMetaClass(MetaClass metaClass)

      Sets the metaclass for a given class.

      Parameters:
        `metaClass` - the new MetaClass
      Since:
        1.6.0