We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 01143d0 commit 0875b54Copy full SHA for 0875b54
1 file changed
src/CompileTimeResolution.java
@@ -1,5 +1,5 @@
1
/**
2
- * This demonstrates how Java polymorphism applies to the compile time type.
+ * This demonstrates how Java polymorphism is limited to the compile time type.
3
*/
4
public class CompileTimeResolution {
5
@@ -10,17 +10,21 @@ public static void main(String args[]) {
10
11
sayHello(a);
12
sayHello(b);
13
+
14
+ // Explicitly casting to the runtime type of the object makes no difference
15
sayHello(c.getClass().cast(c));
16
}
17
18
private static void sayHello(SomethingA a) {
19
System.out.println("Hello A");
20
21
22
+ // Never called
23
private static void sayHello(SomethingB b) {
24
System.out.println("Hello B");
25
26
27
28
private static void sayHello(SomethingC c) {
29
System.out.println("Hello C");
30
0 commit comments