示例

public class ClassA {
Object o;
String s;
public void methodA() {

s = (String) o;
// ...
}

}
解决方案 确保对象 o 是字符串
示例

public class ClassA {
String s;
Object o;
public void methodA() {

if (o instanceof String){
s = (String) o;
// ...

}

}