S
stev.glasow
Gast
Hi,
folgender Code:
Ausgabe ist 5.
Wie kann ich es unterbinden, dass man Point p zu PointImpl casten kann, sprich das man nicht mehr die setX() aufrufen kann. Ich wollte mit dem Interface eigentlich erzwingen das man damit die Koordinaten nur lesen kann.
Wer KANN helfen?
PS: zum Thema kann-Wiederholung:
[schild=2 fontcolor=000000 shadowcolor=C0C0C0 shieldshadow=1] es ist 2:53 Uhr[/schild]
nacht.
folgender Code:
Code:
public interface Point {
public float getX();
public float getY();
}
///////////////////////
public class PointImpl implements Point{
private float x,y;
public float getX(){
return x;
}
public float getY(){
return y;
}
public void setX(float val){
x = val;
}
public void setY(float val){
x = val;
}
}
///////////////////////
public class Test{
public static void main(String[] args){
Point p = ppp();
PointImpl pl = (PointImpl)p;
pl.setX(5);
System.out.println(p.getX());
}
static Point ppp(){
return new PointImpl();
}
}
Wie kann ich es unterbinden, dass man Point p zu PointImpl casten kann, sprich das man nicht mehr die setX() aufrufen kann. Ich wollte mit dem Interface eigentlich erzwingen das man damit die Koordinaten nur lesen kann.
Wer KANN helfen?
PS: zum Thema kann-Wiederholung:
[schild=2 fontcolor=000000 shadowcolor=C0C0C0 shieldshadow=1] es ist 2:53 Uhr[/schild]
nacht.