gpt4 book ai didi

java - 本地方法可以调用私有(private)方法吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:04:53 24 4
gpt4 key购买 nike

我知道在 JAVA 中“原生”是一个特殊的东西。它可以做很多事情。但我现在无法阅读它。我不知道如何......我知道它可以调用 JAVA 中的其他方法。我的问题是:它可以调用私有(private)方法吗?如果是,那么只能在同一个类(class)或任何其他类(class)?如果它可以调用其他人,那么这是否是一个危险的问题?也就是说,它违反了规则。我在哪里可以获得更多关于 NATIVE 的信息?谁能给我一个链接?

最佳答案

JNI Programmer's Guide and Specification在“10.9 违反访问控制规则”中这样说:

"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?

任何类(class)。

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

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

关于java - 本地方法可以调用私有(private)方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12208387/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com