Skip to content

Instantly share code, notes, and snippets.

@jberkel
Created April 6, 2011 10:22
Show Gist options
  • Select an option

  • Save jberkel/905438 to your computer and use it in GitHub Desktop.

Select an option

Save jberkel/905438 to your computer and use it in GitHub Desktop.
daily WTF
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();
}
@robb
Copy link
Copy Markdown

robb commented Apr 6, 2011

but that cast has to be in there because list.get() returns an Object without a better generic, doesn’t it?
edit: which is then coerced to the primitive because Integer.toString() expects an int… omg

At least he was using a StringBuilder…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment