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(); | |
} |
yes, and also casting to Integer and then passing it to Integer.toString()
. object oriented programming, we can haz it. The other wtf is that Android already has support for it (TextUtils)
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
What’s the WTF? Not calling
toString()
on everything?