This does not compile, any suggestion appreciated.
... List list = getList(); return (List) list;
Compil
As others have pointed out, you cannot savely cast them, since a List isn't a List. What you could do, is to define a view on the list that does in-place type checking. Using Google Collections that would be:
List
return Lists.transform(list, new Function() { public Customer apply(Object from) { if (from instanceof Customer) { return (Customer)from; } return null; // or throw an exception, or do something else that makes sense. } });