什么时候向下转型会被允许？

From Stackoverflow -> https://stackoverflow.com/questions/380813/downcasting-in-java

Object o = getSomeObject();
String s = (String) o; // this is allowed because o could reference a String


Object o = new Object();
String s = (String) o; // this will fail at runtime, because o doesn't reference a String


Object o = "a String";
String s = (String) o; // this will work, since o references a String


Integer i = getSomeInteger();
String s = (String) i; // the compiler will not allow this, since i can never reference a String.