Java内部的等效项 [英] Equivalent of internal in java

查看:80
本文介绍了Java内部的等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于Java中的方法,C#中可用的内部访问修饰符等效吗?

What is equivalent of internal access modifier available in C# for method in Java?

(我知道默认值,即方法,无任何范围的变量都具有访问,但我正在寻找与之等效的关键字)

(I know default i.e. methods, variables without any scope are having package access but I am looking for keyword equivalent)

我们如何实现受保护的内部方法是否在Java中作用域?

How can we achieve methods with protected internal scope in Java?

推荐答案

Java中没有等效的程序集,因此不能

There's no equivalent of an assembly in Java, so there can't be an equivalent of an access modifier which makes a member available within an assembly.

与内部修饰符最接近的 c

与受保护的内部最接近的是受保护的(但同样基于软件包)。请注意,Java 中的受保护的自动提供了对该程序包的访问权限-Java中没有什么比C#的 protected受限制的多(就子类而言,仅 可用。)

The closest you can get to protected internal is protected (but again based on package). Note that protected in Java also gives access to the package automatically - there's nothing in Java which is as restrictive as C#'s protected (in terms of only being available within subclasses).

来自JLS 6.6.2 (重点是我的):


对象的受保护成员或构造函数只能通过负责实现的代码从声明其的包外部访问

换句话说,在声明它的包中,所有代码都可以访问它。

In other words, within the package in which it is declared, it's accessible to all code.

这篇关于Java内部的等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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