This is the mail archive of the
mailing list for the Kawa project.
Re: "foo" as string
Luke Gorrie <firstname.lastname@example.org> writes:
> To me it doesn't seem sloppy, it actually seems more intuitive/natural
> than the scheme symbol -> java string mapping. But that's me - I'd
> quite like to have them both coerce.
The quetsion is: Do you want to handle null? If so, calling toString
will not work, though you could call String.valueOf. That produces
"null" given a null pointer, which is not always what you want:
Sometimes you want "null", sometimes a null pointer, sometimes an
exception. That is one reason it may be best to leave it to the
Kawa does it make it possible to define new coercions and use them as
type specifiers. It already has <String> (calls toString),
<java.lang.String> (casts to String), <string> (casts to FString).
You could define a new coercion that calls String.valueOf.