Class CastUtils


  • public class CastUtils
    extends Object

    Helper class for casting

    Since:
    2.0
    Author:
    Andreas Pointner
    • Constructor Detail

      • CastUtils

        public CastUtils()
    • Method Detail

      • cast

        public <S,​T> T cast​(S source)

        Cast any given source to any type

        Supports to cast elements:
             Object o = "abc";
             String s = cast(o);
         

        Supports to cast generic types:

             List<Object> oList = ...
             List<String> sList = cast(oList);
         
        Type Parameters:
        S - the source type
        T - the target type
        Parameters:
        source - the element to be casted
        Returns:
        the casted result
        Throws:
        ClassCastException - if the cast fails