我觉得问这个问题很愚蠢,但我真的不明白这个问题。编译它给了我 ClassCastExeption
这是超级班
package elements;
import persistence.postgres.DataSource;
import persistence.postgres.IdBroker;
import persistence.postgres.PersistenceException;
import util.Util;
public class Hotspot {
private double lat;
private double lng;
private long id;
private String username;
private String time_stamp;
private String point_of_interest;
private String comment;
public Hotspot(double lat, double lng, String username, String comment, String p_o_i) {
this.lat = lat;
this.lng = lng;
this.username = username;
try {
this.id = IdBroker.getId(new DataSource().getConnection());
} catch (PersistenceException e) {
e.printStackTrace();
}
time_stamp = Util.timeStamp();
this.comment = comment;
this.point_of_interest = p_o_i;
}
public Hotspot(double lat, double lng, String username, long id, String time_stamp) {
this.lat = lat;
this.lng = lng;
this.username = username;
this.id = id;
this.time_stamp = time_stamp;
}
//Getter Setter for all variable and HashCode/Equals
}
这是子类
package persistence.postgres;
import elements.Details;
import elements.Hotspot;
public class HotspotProxy extends Hotspot {
private HotSpotDAOpostgres hsd;
private Details details;
//insert
public HotspotProxy(double lat, double lng, String username, String comment, String poi) {
super(lat, lng, username, comment, poi);
this.hsd = new HotSpotDAOpostgres();
}
//Retrieve
public HotspotProxy(double lat, double lng, String username, long id, String time_stamp) {
super(lat, lng, username, id, time_stamp);
this.hsd = new HotSpotDAOpostgres();
}
public String getPointOfInterest() {
redifined method
}
public String getComment() {
//redifined method
}
}
这给了我错误
Hotspot h = new Hotspot(31.124, 43.123, "name", "comment", "point of interest");
HotspotProxy hp = (HotspotProxy)h;
请告诉我我失败的地方。感谢您的任何建议