Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

Re: [groovy-user] DSL / Implicit type casting

Martin C. Martin

2010-03-13

Replies: Find Java Web Hosting

Author LoginPost Reply
$12 is a valid variable name in Java, and in Groovy too, although its
use is discouraged.

On 3/13/2010 2:42 PM, MichaelM wrote:
>
> In an application I am providing, users (not Java programmers) will create
> scripts for certain calculations.
> The scripts will use a Money class, and I am trying to make this as painless
> as
> possible for the users. Money is not multi-currency, the constructor takes a
> BigDecimal.
> Instead of:
> def a = new Money(12.50)
> I would like to be able to support a syntax such as one of the following:
>
> def b = $12.50 // This would be ideal
> Money c = 12.50 // Automatic type casting
> def d = 12.50 as Money //
>
> Any suggestions how to get one of these to work? Alternative syntax
> suggestions are also welcome.
>
> I've looked at these ones, but don't really find them acceptable:
>
> def e = [12.50] as Money // Groovy willl take list and match to constructor
> def f = 12.50.toMoney() // Add toMoney to BigDecimal.metaclass
>
> Thanks,
> M.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.