5 ms·
Java does not allow using reflection to access private fields !? Dude, just use C#.
by Stranger2013 13y ago
Java does not allow using reflection to access private fields !? Dude, just use C#.
- csense 13y agoYou 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 http://en.wikipedia.org/wiki/Javascript#JavaScript_and_Java
- yareally 13y agoYou can access them, it will just throw exceptions you have to catch[1]. [1]http://stackoverflow.com/questions/1196192/how-do-i-read-a-private-field-in-java http://stackoverflow.com/questions/1196192/how-do-i-read-a-p...