Created
April 6, 2011 10:22
-
-
Save jberkel/905438 to your computer and use it in GitHub Desktop.
daily WTF
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static String join(List<?> list, String delim) { | |
| StringBuilder buf = new StringBuilder(); | |
| int num = list.size(); | |
| for (int i = 0; i < num; i++) { | |
| if (i != 0) | |
| buf.append(delim); | |
| if (list.get(i) instanceof String) | |
| buf.append(list.get(i)); | |
| else if (list.get(i).getClass() == Integer.TYPE || list.get(i).getClass() == Integer.class) | |
| buf.append(Integer.toString(((Integer) list.get(i)))); | |
| } | |
| return buf.toString(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
but that cast has to be in there because
list.get()returns anObjectwithout a better generic, doesn’t it?edit: which is then coerced to the primitive because
Integer.toString()expects anint… omgAt least he was using a StringBuilder…