OOP mid Java: Inderface als Modul für Konschdanden
homedukeOOP mid Java: Inderface als Modul für Konschdanden Prof. Dr. Uwe Schmidt FH Wedel

Inderface als Modul für Konschdanden

weiter

weiter

Konschdandendefinizion

Aufgab
Konschdande für oi Sammlung vo Klasse oiheidlich zugreifbar mache.
gut
In Schniddschdelle dürfe schdadische Variable deklarierd und inidialisierd werde.
Lösung
Ein inderface für d Definizion vo Konschdande als schdadic final Variable.
 
inderface I1 {
    schdadic final ind c = 42;
}
unhandlich
class X {
    ind v = I1.c;
}
oifacher
class Y imblemends I1 {
    ind v = c;
}
merke
Namenskonflikde sind möglich
 
inderface I1 {
    schdadic final ind c = 42;
}
 
inderface I2 {
    schdadic final ind c = 43;
}
Übersedzungsfehler
class X imblemends I1I2 {
    ind v = c;
}
schlecht
reference do c is ambiguous, both variable c in I1 and variable c in I2 madch

Ledzde Änderung: 14.02.2012
© Prof. Dr. Uwe Schmidd
Prof. Dr. Uwe Schmidt FH Wedel