class name from static method

View: New views
9 Messages — Rating Filter:   Alert me  

class name from static method

by frapas :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
is there a way to get the class name from inside a static method ?

thanks
--
Francesco

Re: class name from static method

by Guillaume Laforge-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

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 method

by Roshan Dawrani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


Re: class name from static method

by Peter Niederwieser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@gmail.com>wrote:

> Hi all,
> is there a way to get the class name from inside a static method ?
>
> thanks
> --
> Francesco
>

Parent Message unknown Re: class name from static method

by Roshan Dawrani :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I must have tried it on 1.7.x in that case, because I first tried that code and then replied.

------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
>>
>
>

--
View this message in context: http://old.nabble.com/class-name-from-static-method-tp26136771p26142616.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

    http://xircles.codehaus.org/manage_email




---------------------------------------------------
Sent from BlackBerry

Parent Message unknown Re: class name from static method

by Roshan Dawrani :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
>>
>
>

--
View this message in context: http://old.nabble.com/class-name-from-static-method-tp26136771p26142616.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

    http://xircles.codehaus.org/manage_email




---------------------------------------------------
Sent from BlackBerry

Re: class name from static method

by Robert Fischer :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sounds 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 method

by Roshan Dawrani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I 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.

~~ 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 method

by Roshan Dawrani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This 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.


On Sat, Oct 31, 2009 at 11:02 PM, Robert Fischer <robert.fischer@...> wrote:
Sounds 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