Overridden methods with nesting categories - No Fluff Just Stuff

Overridden methods with nesting categories

Posted by: Andres Almiray on November 28, 2007

Categories are one of the options Groovy offers to let you add dynamic methods to classes at runtime, most often than not in a temporary way (unless of course you launch your app with a wrapping category as groovlets do), so no need to mess with MetaClasses (though EMC gives you more control).

Prior to 1.1-rc-3 nesting categories had some problems, and if you overrode a method withing the nested category then you were for a world of pain as it blew up with exceptions. But as I said, that was before, now its a different matter, you can have nested categories and at the same time override a method from the parent category inside the child category. Why is this feature useful? think testing.
Here is a simple example on nested categories

Simple, yet powerful.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »