File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes How does Groovy deals with Final Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "How does Groovy deals with Final Classes" Watch "How does Groovy deals with Final Classes" New topic
Author

How does Groovy deals with Final Classes

Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

I was amazed the way groovy's Trait allows us to extend behavior of any object.

For example:

Output: Parent: Hello Groovy

HelloChild is a final class ,I want to understand the way groovy implements this feature. According to my understanding when groovy deals with 'as' clause
it creates a proxy which extends the instance class (HelloChild) & implements the Trait. But since HelloChild is a final class i am not sure of how it works.
May be through some byte code instrumentation ? Not sure. Would be great if any ranchers knows of the internals and share their knowledge.

Regards,
Shroff.


OCJP-90%,OCPWCD-95%
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

I don't think Groovy is extending the class. This DZone article includes the phrase "A class can be composed out of multiple traits". Which implies that the proxy is wrapping and not subclassing. Not sure though.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Sagar Shroff
Ranch Hand

Joined: Jun 07, 2011
Posts: 208

That sounds correct. Thanks Jeanne.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does Groovy deals with Final Classes