Extra comments
This commit is contained in:
parent
f5d5e87fa4
commit
0b1fb6c74a
|
@ -3,7 +3,6 @@ public class Main {
|
|||
// I - Doesn't work because downcast needs to be explicitly declared
|
||||
// ClassC c = new ClassD();
|
||||
// ClassE e = c;
|
||||
// ClassE e = (ClassE) c;
|
||||
|
||||
// II - Can´t upcast because they are from different family branches
|
||||
// ClassB b = new ClassE();
|
||||
|
@ -14,21 +13,18 @@ public class Main {
|
|||
// a.print(12, "there"); // Ok
|
||||
// a.print(88); // Compilation error
|
||||
|
||||
// IV - We do not have access to a print(String) from the ref C, even though it was downcasted to the obj G
|
||||
// ObjectType <- ReferenceType
|
||||
// Compiler always keep tracking of ObjectType
|
||||
// While only during Runtime that we will check and execute the ReferenceType
|
||||
// IV -
|
||||
// ClassA a = new ClassC(); // Ok -> Upcast A<-C
|
||||
// ClassG g = (ClassG)a; // Ok -> Downcast G<-(A<-C)
|
||||
// g.print("hello"); // RunTime error: trick
|
||||
// Upcast is prone to Compiler error
|
||||
// ClassG g = (ClassG)a; // Compile Error on some JDKs -> Downcast G<-(A<-C)
|
||||
// g.print("hello"); // RunTime error
|
||||
// Upcast is prone to Compiler error and Runtime error
|
||||
// Downcast is prone to Runtime error
|
||||
|
||||
|
||||
// V - We lost track of the print(string, string) in C become it become a A first
|
||||
// ClassA a = new ClassC(); // ok
|
||||
// ClassG g = (ClassG)a; // ok
|
||||
// g.print("hello", "there"); // Runtime error: trick
|
||||
// ClassG g = (ClassG)a; // Compile Error on some JDKs
|
||||
// g.print("hello", "there"); // Runtime error
|
||||
|
||||
// VI
|
||||
// ClassA a = new ClassF(); // OK
|
||||
|
|
Loading…
Reference in New Issue