有没有一种方法可以将方法声明为“友好"?在Java中? [英] Is there a way to declare a method "friendly" in Java?

查看:75
本文介绍了有没有一种方法可以将方法声明为“友好"?在Java中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可以将属性设置为publicfriendlyprivate以指定其可见性.

有没有一种方法可以声明friendly方法?我希望只能从同一包的类的对象访问它.

谢谢您,这里的初学者:(.

解决方案

通过不输入可见性修饰符,Java使用包私有作用域

查看以下文章

如评论中所述,无法将方法标记为友好".但是出于您的需要,package-private就足够了.

I know that attributes can be set public, friendly or private to specify its visibility.

Is there a way I can declare a friendly method? I want it to be accessible only from objects of classes of the same package.

Thanks you, a beginner here :(.

解决方案

By not entering a visiblity modifier Java uses the package private scope

Check out the following article

Edit: As mentioned in the comments, there is no way to mark a method as "friendly". But for your needs, package-private will suffice.

这篇关于有没有一种方法可以将方法声明为“友好"?在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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