|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
class name from static methodHi all,
is there a way to get the class name from inside a static method ? thanks -- Francesco
|
|
|
Re: class name from static methodHi,
this.name should work (this also works in static contexts and refer to the current class) On Fri, Oct 30, 2009 at 21:58, Francesco Pasqualini <frapas@...> wrote: > Hi all, > is there a way to get the class name from inside a static method ? > thanks > -- > Francesco -- Guillaume Laforge Groovy Project Manager Head of Groovy Development at SpringSource http://www.springsource.com/g2one --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: class name from static methodYes, there is.
================== class Foo { static m() { println this.name } } Foo.m() ================== This works because in static context, groovy maps calls on "this" to calls on the class. -- Roshan On Sat, Oct 31, 2009 at 2:28 AM, Francesco Pasqualini <frapas@...> wrote: Hi all, |
|
|
Re: class name from static methodDoesn't work for me (Groovy 1.6.6-SNAPSHOT). The following:
class Foo { static main(args) { println this.name } } results in: java.lang.ClassCastException: java.lang.Class cannot be cast to groovy.lang.GroovyObject However, "println this.getName()" does work. Cheers, Peter
|
|
|
|
|
|
|
|
|
Re: class name from static methodSounds like a JIRA to me.
~~ Robert Fischer, Smokejumper IT Consulting. Enfranchised Mind Blog http://EnfranchisedMind.com/blog Grails Expert Retainer Services http://smokejumperit.com/grails-retainer/ roshandawrani@... wrote: > I just noticed that you are invoking this.name from main(), so that bit was different and I had tried it a non-main() method. So issue you have pointed out may be in both 1.6 and 1.7. > > It should behave same, though. > > I will give it a try later and see what makes main() different. > > > ------Original Message------ > From: Peter Niederwieser > To: user@... > ReplyTo: user@... > Subject: Re: [groovy-user] class name from static method > Sent: Oct 31, 2009 7:36 PM > > > Doesn't work for me (Groovy 1.6.6-SNAPSHOT). The following: > > class Foo { > static main(args) { > println this.name > } > } > > results in: > > java.lang.ClassCastException: java.lang.Class cannot be cast to > groovy.lang.GroovyObject > > However, "println this.getName()" does work. > > Cheers, > Peter > > > Roshan Dawrani-2 wrote: >> Yes, there is. >> >> ================== >> class Foo { >> static m() { >> println this.name >> } >> } >> >> Foo.m() >> ================== >> >> This works because in static context, groovy maps calls on "this" to calls >> on the class. >> >> -- Roshan >> >> On Sat, Oct 31, 2009 at 2:28 AM, Francesco Pasqualini >> <frapas@...>wrote: >> >>> Hi all, >>> is there a way to get the class name from inside a static method ? >>> >>> thanks >>> -- >>> Francesco >>> >> > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: class name from static methodI created GROOVY-3863 for it.
On Sat, Oct 31, 2009 at 11:02 PM, Robert Fischer <robert.fischer@...> wrote: Sounds like a JIRA to me. |
|
|
Re: class name from static methodThis issue should be found fixed in current 1.6.6 and 1.7-rc-1 snapshots now.
-- Roshan On Sat, Oct 31, 2009 at 11:06 PM, Roshan Dawrani <roshandawrani@...> wrote: I created GROOVY-3863 for it. |
| Free embeddable forum powered by Nabble | Forum Help |