square / javapoet

A Java API for generating .java source files.
Apache License 2.0
10.81k stars 1.37k forks source link

$S-ing a -Spec type puts its toString into a string #728

Open JakeWharton opened 5 years ago

JakeWharton commented 5 years ago

I feel like this is never what you want, and that it should behave like "$N". Or is this too magical and I should just be using "$N"?

ronshapiro commented 5 years ago

FWIW, I wrote an ErrorProne check to detect usages of mistaken codeblock arguments and I think it would catch this. In my mind, $S should almost always be a String (or maybe CharSequence).

On Tue, Jun 4, 2019, 2:05 PM Jake Wharton notifications@github.com wrote:

I feel like this is never what you want, and that it should behave like "$N". Or is this too magical and I should just be using "$N"?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/javapoet/issues/728?email_source=notifications&email_token=AAGBRXNEJOD3DU47UMJHO7LPY2VE3A5CNFSM4HS7TQK2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4GXTALZA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGBRXLTOCEFZCI76UA4DIDPY2VE3ANCNFSM4HS7TQKQ .

sormuras commented 5 years ago

[...] $S should almostalways be a String (or maybe CharSequence).

This.

JakeWharton commented 5 years ago

I don't agree. The implicit behavior of toString-ing is fine. It's like string concatenation. My issue here is more like how toString on array is useless and has to be special cased. toString() on JavaPoet types in $S are useless and could be special cased.