Java中如何限制开发者使用反射访问私有方法和构造函数? [英] How to restrict developers to use reflection to access private methods and constructors in Java?

查看:23
本文介绍了Java中如何限制开发者使用反射访问私有方法和构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 中如何限制开发者使用反射访问私有方法和构造函数?

How to restrict developers to use reflection to access private methods and constructors in Java?

使用普通的 Java 代码,我们无法访问类之外的私有构造函数或私有方法.但是通过使用反射,我们可以访问 Java 类中的任何私有方法和构造函数.

Using normal Java code we can't access private constructors or private methods outside of a class. But by using reflection we can access any private methods and constructors in a Java class.

那么我们如何才能为我们的 Java 代码提供安全性?

So how can we give security to our Java code?

推荐答案

使用 SecurityManager 和足够严格的 安全策略.

教程中有一个简短摘要和大量信息在安全文档中.

There's a short summary in the tutorial and extensive information in the security documentation.

这篇关于Java中如何限制开发者使用反射访问私有方法和构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆