groovy

Adding instance methods to classes

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.1-beta-2
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

Sam introduced the "use" keyword but I'd like to have a somewhat more permanent ways because "use" is quite noisy in scripts and can get overused quite easily.

I quickly developed a simple way to add methods just like the DefaultGroovyMethods does. Its not perfect cause it requires a system property but it works quite nicely.

See patch&testcase here:

http://lists.codehaus.org/pipermail/groovy-dev/2004q2/002055.html

Activity

Hide
Bing Ran added a comment -

A couple of ways to avoid using a special system property:

1. The Groovy runtime designate a special package (e.g., groovy.lang.extension) as a namespace where any class in the package is considered Groovy runtime extensions. Anytime a user would add his own new methods for java classes, he/she creats a new class in that namespace.

2. The Groovy runtime designate a special directory in the fielsystem and any class files or jars files are searched for
extensions. This is similar to java lib/ext mechanism.

Of course, all these are subjected to groovy runtime security policy.

Show
Bing Ran added a comment - A couple of ways to avoid using a special system property: 1. The Groovy runtime designate a special package (e.g., groovy.lang.extension) as a namespace where any class in the package is considered Groovy runtime extensions. Anytime a user would add his own new methods for java classes, he/she creats a new class in that namespace. 2. The Groovy runtime designate a special directory in the fielsystem and any class files or jars files are searched for extensions. This is similar to java lib/ext mechanism. Of course, all these are subjected to groovy runtime security policy.
Hide
Paul King added a comment -

Now handled by ExpandoMetaClass, see http://groovy.codehaus.org/ExpandoMetaClass

Show
Paul King added a comment - Now handled by ExpandoMetaClass, see http://groovy.codehaus.org/ExpandoMetaClass

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: