«« Next » « Previous
«« Next » « Previous

Link Details

Link 95288 thumbnail
User 214988 avatar

By puredanger
via platypusinnovation.com
Published: Jul 18 2008 / 16:08

A look at one of the obscure corners of Java - how to access private fields and methods from outside a class.
  • 7
  • 1
  • 971
  • 261

Comments

Add your comment
User 214988 avatar

puredanger replied ago:

0 votes Vote down Vote up Reply

There's no comment feature on the site, but I thought it was worth mentioning that

a) it is not possible to modify *final* fields in all versions of the JDK. This was originally supported, then pulled in (I think) 1.4, then added back in (I think) 1.5.

b) final values are compiled into other classes compiled with that class. So you can change the value of it and other classes may still see the original value. Thus, this is *really* unlikely to work in a way you expect.

Note, these apply to final fields only.

User 61474 avatar

William Louth replied ago:

0 votes Vote down Vote up Reply

I think you should qualify (a) because it is possible but not via reflection.

User 278075 avatar

eabarquez replied ago:

0 votes Vote down Vote up Reply

That's a funny title. Lol.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Voters For This Link (7)



Voters Against This Link (1)