r/programming • • May 10 '18

Java: Executing code in comments?!

http://programming.guide/java/executing-code-in-comments.html
260 Upvotes

84 comments sorted by

View all comments

Show parent comments

0

u/[deleted] May 11 '18

[deleted]

1

u/[deleted] May 11 '18

It's defined but makes no sense. It's also doing it wrong. //\z isn't a correct escape so it should get an error. If you say it shouldn't then //\u0ashouldn't either because it's also an invalid escape however it does.

Its an unnecessary and incorrect step. If 'Hello 💩' works then I don't see why it needs to do decoding outside of string literals. In fact it can't even decode that correct either as \U0001F4A9 gets a compile error.

0

u/[deleted] May 11 '18

[deleted]

1

u/[deleted] May 11 '18

I'm calling bullshit. 1) Noone reads or writes \u1234 themselves 2) I can't imagine the compiler throwing a fit that 8bit characters are in the source file in a comment (ANSI is 8bit IIRC do this pushes my point) so only the IDE would care what encoding the file is