10 July 2012

Primitives in Java doesn't swim in the same direction

public boolean removeBuConfigurationByIds(long[] id) throws DBException {
   if (id == null || id.length == 0)
       return false;
   String ids = AdminUtil.join(id, ", ");
The above code produce compile-time error at line 4
Provided that the following is the method join:
ublic static <T> String join(T[] arr, String separator) {
        if (arr == null || arr.length == 0)
            return null;

        StringBuffer sb = new StringBuffer(arr.length);

        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
            if (i != arr.length - 1)
                sb.append(separator);
        }
        return sb.toString();
    }
This is because primitives in java couldn't be presented by Generics! (C++ do )
Post a Comment