July 2013
Intermediate to advanced
370 pages
8h 27m
English
Dynamic typing and dynamic languages change how objects respond to method calls.
Groovy supports polymorphism, like Java does, but it goes far beyond simply dispatching methods based on the target object’s type. Let’s look at polymorphism in Java:
| TypesAndTyping/Employee.java | |
| | // Java code |
| | public class Employee { |
| | public void raise(Number amount) { |
| | System.out.println("Employee got raise"); |
| | } |
| | } |
The Employee class’s
raise
method
simply reports that it was called.
Now look at the Executive class:
| TypesAndTyping/Executive.java | |
| | // Java code |
| | public class Executive extends Employee { |
| | public void raise(Number amount) { |
| | System.out.println("Executive got raise"); |
| | } |
| | |
| | public ... |
Read now
Unlock full access