ClassUtil (FreeMarker 2.3.23 API)
Date: 2015-07-05

freemarker.template.utility

## Class ClassUtil

- java.lang.Object
- - freemarker.template.utility.ClassUtil

-     public class ClassUtil
      extends Object

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Class` | `boxingClassToPrimitiveClass(Class boxingClass)` The exact reverse of `primitiveClassToBoxingClass(java.lang.Class)`.
    `static Class` | `forName(String className)` Similar to `Class.forName(java.lang.String)`, but attempts to load through the thread context class loader.
    `static String` | `getFTLTypeDescription(TemplateModel tm)` Returns the type description of a value with FTL terms (not plain class name), as it should be used in type-related error messages and for debugging purposes.
    `static String` | `getShortClassName(Class pClass)` Same as `getShortClassName(pClass, false)`.
    `static String` | `getShortClassName(Class pClass, boolean shortenFreeMarkerClasses)` Returns a class name without "java.lang." and "java.util." prefix, also shows array types in a format like `int[]`; useful for printing class names in error messages.
    `static String` | `getShortClassNameOfObject(Object obj)` Same as `getShortClassNameOfObject(pClass, false)`.
    `static String` | `getShortClassNameOfObject(Object obj, boolean shortenFreeMarkerClasses)` `getShortClassName(Class, boolean)` called with `object.getClass()`, but returns the fictional class name `Null` for a `null` value.
    `static boolean` | `isNumerical(Class type)` Tells if a type is numerical; works both for primitive types and classes.
    `static Class` | `primitiveClassToBoxingClass(Class primitiveClass)` Gets the wrapper class for a primitive class, like `Integer` for `int`, also returns `Void` for `void`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### forName

          public static Class forName(String className)
                               throws ClassNotFoundException

      Similar to `Class.forName(java.lang.String)`, but attempts to load through the thread context class loader. Only if thread context class loader is inaccessible, or it can't find the class will it attempt to fall back to the class loader that loads the FreeMarker classes.
      Throws:
        `ClassNotFoundException`

    - #### getShortClassName

          public static String getShortClassName(Class pClass)

      Same as `getShortClassName(pClass, false)`.
      Since:
        2.3.20

    - #### getShortClassName

          public static String getShortClassName(Class pClass,
                                                 boolean shortenFreeMarkerClasses)

      Returns a class name without "java.lang." and "java.util." prefix, also shows array types in a format like `int[]`; useful for printing class names in error messages.
      Parameters:
        `pClass` - can be `null`, in which case the method returns `null`.
        `shortenFreeMarkerClasses` - if `true`, it will also shorten FreeMarker class names. The exact rules aren't specified and might change over time, but right now, `freemarker.ext.beans.NumberModel` for example becomes to `f.e.b.NumberModel`.
      Since:
        2.3.20

    - #### getShortClassNameOfObject

          public static String getShortClassNameOfObject(Object obj)

      Same as `getShortClassNameOfObject(pClass, false)`.
      Since:
        2.3.20

    - #### getShortClassNameOfObject

          public static String getShortClassNameOfObject(Object obj,
                                                         boolean shortenFreeMarkerClasses)

      `getShortClassName(Class, boolean)` called with `object.getClass()`, but returns the fictional class name `Null` for a `null` value.
      Since:
        2.3.20

    - #### getFTLTypeDescription

          public static String getFTLTypeDescription(TemplateModel tm)

      Returns the type description of a value with FTL terms (not plain class name), as it should be used in type-related error messages and for debugging purposes. The exact format is not specified and might change over time, but currently it's something like `"string (wrapper: f.t.SimpleScalar)"` or `"sequence+hash+string (ArrayList wrapped into f.e.b.CollectionModel)"`.
      Since:
        2.3.20

    - #### primitiveClassToBoxingClass

          public static Class primitiveClassToBoxingClass(Class primitiveClass)

      Gets the wrapper class for a primitive class, like `Integer` for `int`, also returns `Void` for `void`.
      Parameters:
        `primitiveClass` - A `Class` like `int.type`, `boolean.type`, etc. If it's not a primitive class, or it's `null`, then the parameter value is returned as is. Note that performance-wise the method assumes that it's a primitive class.
      Since:
        2.3.21

    - #### boxingClassToPrimitiveClass

          public static Class boxingClassToPrimitiveClass(Class boxingClass)

      The exact reverse of `primitiveClassToBoxingClass(java.lang.Class)`.
      Since:
        2.3.21

    - #### isNumerical

          public static boolean isNumerical(Class type)

      Tells if a type is numerical; works both for primitive types and classes.
      Parameters:
        `type` - can't be `null`
      Since:
        2.3.21