|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Apr 2008
Città: MilanoMilano Compravendite: 17
Messaggi: 3564
|
[Java][Pseudocodice] Type checking a compile time
Ciao amicici.
Se avessi il seguente scenario: class TypeA{...} class TypeB extends TypeA{...} class TypeC extends TypeB{...} con le seguenti dichiarazioni: TypeA a; TypeB b; TypeC c; Il compilatore considererebbe corretti i seguenti assegnamenti? b=a; c=b; Grazie.
__________________
CASE Cooler Master HAF-X & Mod LianLi HYDRO Corsair H100 PSU Corsair AX850W MB ASRock Z170 EXTREME 4
CPU i7 6700K VGA MSI GTX 1080 GAMING X RAM DDR3 2x8GB HyperX SSD OCZ Revodrive 80GB HDD RAID0 WD CB 1Tb DLP Optoma GT720 VR Oculus Rift MISCELLANEOUS 3D Vision 2 + Asus Xonar D2X + Sennheiser |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: May 2001
Messaggi: 12883
|
Tu che ne pensi?
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2008
Città: MilanoMilano Compravendite: 17
Messaggi: 3564
|
Domanda interessante.
Secondo me no: darebbe errore.
__________________
CASE Cooler Master HAF-X & Mod LianLi HYDRO Corsair H100 PSU Corsair AX850W MB ASRock Z170 EXTREME 4
CPU i7 6700K VGA MSI GTX 1080 GAMING X RAM DDR3 2x8GB HyperX SSD OCZ Revodrive 80GB HDD RAID0 WD CB 1Tb DLP Optoma GT720 VR Oculus Rift MISCELLANEOUS 3D Vision 2 + Asus Xonar D2X + Sennheiser Ultima modifica di ciccionamente90 : 13-07-2013 alle 21:29. |
|
|
|
|
|
#4 |
|
Senior Member
Iscritto dal: Oct 2006
Città: milano
Messaggi: 1439
|
b è sottotipo di a e c è sottotipo di b, secondo me nessun problema!
|
|
|
|
|
|
#5 |
|
Senior Member
Iscritto dal: Apr 2008
Città: MilanoMilano Compravendite: 17
Messaggi: 3564
|
Il problema "di correttezza" dell'assegnamento in generale ci sarebbe (il tipo apparente dovrebbe essere sopra-tipo del tipo effettivo). Per quale motivo riterresti che a compile-time tale check non venga effettuato?
__________________
CASE Cooler Master HAF-X & Mod LianLi HYDRO Corsair H100 PSU Corsair AX850W MB ASRock Z170 EXTREME 4
CPU i7 6700K VGA MSI GTX 1080 GAMING X RAM DDR3 2x8GB HyperX SSD OCZ Revodrive 80GB HDD RAID0 WD CB 1Tb DLP Optoma GT720 VR Oculus Rift MISCELLANEOUS 3D Vision 2 + Asus Xonar D2X + Sennheiser |
|
|
|
|
|
#6 |
|
Senior Member
Iscritto dal: May 2001
Messaggi: 12883
|
Prova
|
|
|
|
|
|
#7 |
|
Senior Member
Iscritto dal: Apr 2008
Città: MilanoMilano Compravendite: 17
Messaggi: 3564
|
Attualmente non ne ho la possibilità.
__________________
CASE Cooler Master HAF-X & Mod LianLi HYDRO Corsair H100 PSU Corsair AX850W MB ASRock Z170 EXTREME 4
CPU i7 6700K VGA MSI GTX 1080 GAMING X RAM DDR3 2x8GB HyperX SSD OCZ Revodrive 80GB HDD RAID0 WD CB 1Tb DLP Optoma GT720 VR Oculus Rift MISCELLANEOUS 3D Vision 2 + Asus Xonar D2X + Sennheiser |
|
|
|
|
|
#8 |
|
Senior Member
Iscritto dal: Jan 2008
Messaggi: 8406
|
No, non è corretto quello che hai scritto.
Corretto sarebbe Codice:
a = new TypeB(); Ovviamente non avrai accesso ai membri previsti dalla classe figlia, ma solo a quelli della classe madre. Quest'ultima frase, ti fa capire perchè l'inverso è impossibile. L'unica cosa che puoi fare è prendere quell'a e assegnarlo successivamente a b ( downcasting ). |
|
|
|
|
|
#9 |
|
Senior Member
Iscritto dal: Apr 2008
Città: MilanoMilano Compravendite: 17
Messaggi: 3564
|
Grazie per la risposta, ma il fatto è che io so che non è corretto, ma non sono certo del fatto che il compilatore se ne accorga.
__________________
CASE Cooler Master HAF-X & Mod LianLi HYDRO Corsair H100 PSU Corsair AX850W MB ASRock Z170 EXTREME 4
CPU i7 6700K VGA MSI GTX 1080 GAMING X RAM DDR3 2x8GB HyperX SSD OCZ Revodrive 80GB HDD RAID0 WD CB 1Tb DLP Optoma GT720 VR Oculus Rift MISCELLANEOUS 3D Vision 2 + Asus Xonar D2X + Sennheiser |
|
|
|
|
|
#10 |
|
Senior Member
Iscritto dal: Jan 2008
Messaggi: 8406
|
|
|
|
|
|
|
#11 |
|
Senior Member
Iscritto dal: Apr 2008
Città: MilanoMilano Compravendite: 17
Messaggi: 3564
|
Grazie mille.
__________________
CASE Cooler Master HAF-X & Mod LianLi HYDRO Corsair H100 PSU Corsair AX850W MB ASRock Z170 EXTREME 4
CPU i7 6700K VGA MSI GTX 1080 GAMING X RAM DDR3 2x8GB HyperX SSD OCZ Revodrive 80GB HDD RAID0 WD CB 1Tb DLP Optoma GT720 VR Oculus Rift MISCELLANEOUS 3D Vision 2 + Asus Xonar D2X + Sennheiser |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 16:33.




















