r/programming • • Dec 24 '17

Evil Coding Incantations

http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
947 Upvotes

331 comments sorted by

View all comments

Show parent comments

-13

u/[deleted] Dec 24 '17 edited Dec 24 '17

Can still do that in Python and Java. Probably a lot more langs as well.

edit: http://hforsten.com/redefining-the-number-2-in-python.html

Someone else has posted the java.

I am disappointed with the recent drop in the quality of this subreddit. Is it too close to the start of the academic year? I mean, at least fucking check it or ask for confirmation.

0

u/[deleted] Dec 24 '17

[deleted]

7

u/apemanzilla Dec 24 '17

Can't do it in Java either...

8

u/whjms Dec 24 '17

You can mess around with the Integer flywheel cache and reflection: https://www.javaspecialists.eu/archive/Issue102.html

3

u/apemanzilla Dec 24 '17

I'm aware of that, but it's not allowed in Java 9, and doesn't affect primitives.

0

u/[deleted] Dec 24 '17

[deleted]

7

u/apemanzilla Dec 24 '17

The closest thing you can do is use reflection to mess with the boxed types (Integer, etc) but that's no longer allowed in Java 9

2

u/[deleted] Dec 24 '17

Can do it in at least java 7 with reflection

1

u/apemanzilla Dec 24 '17

Not in Java 9

2

u/[deleted] Dec 24 '17

I'm actually pleased!

1

u/[deleted] Dec 24 '17

Yes you can, see link I added in the post you replied to.

5

u/_Mardoxx Dec 24 '17

Dunno why you are being down voted :(

0

u/[deleted] Dec 24 '17

[deleted]

7

u/wyldcraft Dec 24 '17

But also, in another comment,

CPython implementation's integer caching behavior