Przykład

public ObjectDowncast_Example( String str ) {
super();
this .str = str;
}

public Object getString(){
return str;
}

private String str;

public static void main(String[] args){
ObjectDowncast_Example example = new ObjectDowncast_Example("Hello World!"); //$NON-NLS-1$
String str = (String)example.getString();
System.out.println( str );
}

Rozwiązanie
Zmień metodę, aby zwracała bieżący typ danych zamiast obiektu java.lang.Object.
Jeśli metoda zwraca obiekty o typach, które nie współużytkują wspólnego interfejsu lub klasy, utwórz nowy interfejs lub klasę i hermetyzuj w nich dany obiekt.

public ObjectDowncast_Solution( String str ) {
super();
this .str = str;
}

public String getString(){
return str;
}

private String str;

public static void main(String[] args){
ObjectDowncast_Solution example = new ObjectDowncast_Solution("Hello World!"); //$NON-NLS-1$
String str = example.getString();
System.out.println( str );
}