Class Generics

java.lang.Object
org.zkoss.lang.Generics

public class Generics extends Object
Utilities to handle generic types, such as converting a non-type object to a generic type without warning.
Since:
6.0.0
Author:
tomyeh
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final <T> Class<T>
    cast(Class cls)
    Returns a type-safe generic class of the given type-less class.
    static final <T> T
    Force to cast an object to the given type.
    static final <T> ThreadLocal<T>
    Returns a type-safe generic thread-local of the given un-typed thread-local.
    static final <T> Collection<T>
    Returns a type-safe generic collection of the given un-typed collection.
    static final <T> Enumeration<T>
    Returns a type-safe generic enumeration of the given un-typed enumeration.
    static final <T> Iterator<T>
    Returns a type-safe generic iterator of the given un-typed iterator.
    static final <T> List<T>
    cast(List list)
    Returns a type-safe generic list of the given un-typed list.
    static final <T> ListIterator<T>
    Returns a type-safe generic list iterator of the given un-typed list iterator.
    static final <K, V> Map<K,V>
    cast(Map map)
    Returns a type-safe generic map of the given un-typed map.
    static final <T> Set<T>
    cast(Set set)
    Returns a type-safe generic set of the given un-typed set.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Generics

      public Generics()
  • Method Details

    • cast

      public static final <T> Class<T> cast(Class cls)
      Returns a type-safe generic class of the given type-less class.
    • cast

      public static final <T> T cast(Object o)
      Force to cast an object to the given type. Notice that it is not safe to use, unless you are sure that o is an instance of T.
    • cast

      public static final <T> Iterator<T> cast(Iterator it)
      Returns a type-safe generic iterator of the given un-typed iterator.
    • cast

      public static final <T> ListIterator<T> cast(ListIterator it)
      Returns a type-safe generic list iterator of the given un-typed list iterator.
    • cast

      public static final <T> Enumeration<T> cast(Enumeration en)
      Returns a type-safe generic enumeration of the given un-typed enumeration.
    • cast

      public static final <T> Collection<T> cast(Collection col)
      Returns a type-safe generic collection of the given un-typed collection.
    • cast

      public static final <T> List<T> cast(List list)
      Returns a type-safe generic list of the given un-typed list.
    • cast

      public static final <T> Set<T> cast(Set set)
      Returns a type-safe generic set of the given un-typed set.
    • cast

      public static final <K, V> Map<K,V> cast(Map map)
      Returns a type-safe generic map of the given un-typed map.
    • cast

      public static final <T> ThreadLocal<T> cast(ThreadLocal tl)
      Returns a type-safe generic thread-local of the given un-typed thread-local.