Příklad

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);
}

Řešení
Změňte metodu, aby vracela skutečný datový typ místo java.lang.Object.
Pokud metoda vrací objekty typů, které nesdílí společné rozhraní nebo třídu, vytvořte nové rozhraní nebo třídu a zapouzdřete v nich objekt.

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);
}