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

3

u/[deleted] May 11 '18

Why the hell is Java decoding/unescaping source code? It literally makes no sense. It doesn't even do it properly. Putting in \z gets me an error because it doesn't exist. Putting \z in a comment works fine. If it's going to decode my source code why the hell isn't it giving me errors on invalid decodes. Java is not doing the wrong thing correctly

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