user2917629
user2917629

Reputation: 942

Groovy basics - runtime behavior and encapsulation

I've been reading "Groovy in Action" by Dierk Koenig. Dierk claims that these are the Groovy tasks that Java cannot perform:

- Changing the runtime behavior of objects after they have been created.

I thought Java has that as well - dynamic dispatch. Can anyone explain how is it different from Java?

- Encapsulating logic in objects in a natural way. 

How is this different from Java? Much appreciate your time to respond if you have a clear answer.

Upvotes: 1

Views: 504

Answers (1)

M A
M A

Reputation: 72884

For the first task:

Changing the runtime behavior of objects after they have been created.

I think you're confusing this Groovy language feature with such concepts as polymorphism in Java. This feature in Groovy allows you, for instance, to replace a method for an existing object at runtime, whereas dynamic dispatch is a core feature of the JVM which allows the runtime to dispatch the correct method call based on the actual type of the object.

For the second task:

Encapsulating logic in objects in a natural way.

I think it's about closures which allow you to store references to code blocks or methods that can be re-used. This feature does not exist in Java.

Upvotes: 3

Related Questions