Edit: Ich stoße auf dieses Problem, wenn ich ein Objekt klonen muss, und ich habe gesucht, aber keine Frage mein Problem zu lösen.Java: Typ vor dem Klon schreiben?
Als ich das Prototyp-Muster in Java lernte, folgte ich einigen Tutorials und bin verwirrt über die Typ-Casting von (Bike)super.clone()
.
Was wird zuerst gemacht? (Bike)super
oder super.clone()
? Warum wird (Bike)
benötigt?
public interface Prototype extends Cloneable
{
public Prototype clone() throws CloneNotSupportedException;
}
public class Bike implements Prototype
{
// Constructor and other methods...
// My question is here
public Prototype clone() throws CloneNotSupportedException {
return (Bike)super.clone();
}
}
Mögliches Duplikat von [Java-Casting-Reihenfolge] (http://stackoverflow.com/questions/5762270/java Casting-Order) – Tom