本机方法可以调用私有方法吗? [英] Can a native method call a private method?

查看:81
本文介绍了本机方法可以调用私有方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在JAVA中本土是一件特别的事。它可以做很多事情。但我现在无法阅读它。我不知道怎么...我知道它可以调用JAVA中的其他方法。我的问题是:它可以调用私有方法吗?如果是YES,那么只在同一个班级或任何其他班级?如果它可以调用其他的,那么这是一个问题,也许它是危险的?也就是说,它打破了规则。我在哪里可以获得更多关于NATIVE的信息?任何人都可以给我看一个链接吗?

I knew that in JAVA "native" is a special thing. It can do a lot of things. But I'm not able to read it right now. I don't know how to... I knew it can call an other mathod in JAVA. My question is: can it call a private method? if it is a YES, then only in the same class or any other classes? if it can call other's, then is it a problem that maybe it's dangerous? that is, it broke the rules. Where can I get more about the NATIVE? can anybody show me a link?

推荐答案

JNI程序员指南和规范在10.9违反访问控制规则中说明了这一点:

The JNI Programmer's Guide and Specification says this in "10.9 Violating Access Control Rules":


JNI不会强制执行类,字段和方法访问控制限制,这些限制可以通过使用私有和最终修饰符在Java编程语言级别表达。有可能编写本机代码来访问或修改对象的字段,即使在Java编程语言级别这样做会导致 IllegalAccessException .JNI的放纵是一个有意识的设计决定,给出该本机代码无论如何都可以访问和修改堆中的任何内存位置。

"The JNI does not enforce class, field, and method access control restrictions that can be expressed at the Java programming language level through the use of modifiers such as private and final. It is possible to write native code to access or modify fields of an object even though doing so at the Java programming language level would lead to an IllegalAccessException. JNI's permissiveness was a conscious design decision, given that native code can access and modify any memory location in the heap anyway."

所以问题的答案是:


可以调用私有方法吗?

Can it call a private method?

是。


如果是是,那么只在同一个班级或任何其他班级?

if it is a YES, then only in the same class or any other classes?

任何类别。


如果是可以打电话给其他人,那么这是一个问题,也许它很危险吗?也就是说,它打破了规则。

if it can call other's, then is it a problem that maybe it's dangerous? that is, it broke the rules.

上面引用的文字清楚地说明了设计者不试图强制执行普通Java访问规则的理由。是的,它有潜在危险,但任何使用JNI都有潜在危险。

The designers' rationale for not attempting to enforce the normal Java access rules is clearly stated in the text quoted above. Yes it is potentially dangerous, but any use of JNI is potentially dangerous.

这篇关于本机方法可以调用私有方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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