Well, I have a class Customer (no base class).
I need to cast from LinkedList to List. Is there any clean way to do this?
Just so you know, I need to cast it
Here's my horrible solution for doing casting. I know, I know, I shouldn't be releasing something like this into the wild, but it has come in handy for casting any object to any type:
public class UnsafeCastUtil {
private UnsafeCastUtil(){ /* not instatiable */}
/**
* Warning! Using this method is a sin against the gods of programming!
*/
@SuppressWarnings("unchecked")
public static T cast(Object o){
return (T)o;
}
}
Usage:
Cat c = new Cat();
Dog d = UnsafeCastUtil.cast(c);
Now I'm going to pray to the gods of programming for my sins...