This commit is contained in:
Marcus Vinicius de Carvalho 2024-10-22 17:31:22 +08:00
parent 68d4c9b733
commit f5d5e87fa4
4 changed files with 13 additions and 7 deletions

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-22" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -14,12 +14,18 @@ public class Main {
// a.print(12, "there"); // Ok
// a.print(88); // Compilation error
// IV
// ClassA a = new ClassC(); // Ok
// ClassG g = new (ClassG)a; // Syntax 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
// 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
// Downcast is prone to Runtime error
// V
// 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