groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul King <>
Subject Re: ShortTypeHandling castToString
Date Wed, 15 Jun 2016 04:32:20 GMT
Yes, it's clearly a bug as can be seen by running an example such as below:

String foo() { Integer }
foo() // ClassCastException

Whereas 'Integer as String' works fine. I have a fix for this in
PR#345 as part of GROOVY-7853, see:

Just waiting for to see if Cédric/Jochen have any comments on the
other parts of that PR since that is an area of the codebase that I am
a little less familiar with.

Cheers, Paul.

On Wed, Jun 15, 2016 at 1:29 AM, Winnebeck, Jason
<> wrote:
> I came across this method in Groovy 2.4.6 in ShortTypeHandling class, I’ve
> never seen it fail but it doesn’t see right to me:
> public static String castToString(Object object) {
>     if (object==null) return null;
>     if (object instanceof Class) return (String) object;
>     return object.toString();
> }
> How can cast to String work if the object is a Class?
> Jason
> ________________________________
> This email message and any attachments are for the sole use of the intended
> recipient(s). Any unauthorized review, use, disclosure or distribution is
> prohibited. If you are not the intended recipient, please contact the sender
> by reply email and destroy all copies of the original message and any
> attachments.

View raw message