This little piece of code compiles, but doesn’t work.
public String[] getNamesOf(Collection people) {
ArrayList<String> names = new ArrayList<String>();
for (Person person : people)
names.add(person.getName());
return (String[]) names.toArray();
}
Now, interesting question: why would a type checking compiler allow this type checking error to pass through?
Update: If you’re seeing this a second time in your feed reader, WP ate my brackets the first time, I fixed it to include the use of generics.