Hacker News new | ask | show | jobs
by Stranger2013 4747 days ago
Java does not allow using reflection to access private fields !? Dude, just use C#.
2 comments

You might be able to do it if you replace the SecurityManager or something.

We may laugh now, but it actually seemed like a good idea at the time.

Remember, a big part of Java's early use case was running untrusted remote code ("Applets") in the browesr without prompting the user (a niche now filled by JavaScript [1] and a declining Flash). Which means you really don't want that code to be able to bypass all your security by using the reflection API to read and write things it's not supposed to.

Applets never really caught on, but now the language features are constrained by backward compatibility.

Also, C# isn't supported on Android AFAIK.

[1] Mostly unrelated to Java despite its name; see http://en.wikipedia.org/wiki/Javascript#JavaScript_and_Java

You can access them, it will just throw exceptions you have to catch[1].

[1]http://stackoverflow.com/questions/1196192/how-do-i-read-a-p...