Java中的接口:无法使已实现的方法受到保护或私有 [英] Interfaces in Java: cannot make implemented methods protected or private

查看:154
本文介绍了Java中的接口:无法使已实现的方法受到保护或私有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道界面必须是公开的。但是,我不希望这样。

I know that an interface must be public. However, I don't want that.

我希望我的实现方法只能从他们自己的包中访问,所以我希望我的实现方法受到保护。

I want my implemented methods to only be accessible from their own package, so I want my implemented methods to be protected.

问题是我无法使接口或实现的方法受到保护。

The problem is I can't make the interface or the implemented methods protected.

什么是解决方法?是否存在与此问题相关的设计模式?

What is a work around? Is there a design pattern that pertains to this problem?

从Java指南中,抽象类也不能完成这项工作。

From the Java guide, an abstract class wouldn't do the job either.

推荐答案

阅读这个

公共访问说明符表示任何包中的任何类都可以使用该接口。如果不这样做指定接口是公共的,您的界面只能访问与接口相同的包中定义的类

"The public access specifier indicates that the interface can be used by any class in any package. If you do not specify that the interface is public, your interface will be accessible only to classes defined in the same package as the interface."

这是你想要的吗?

这篇关于Java中的接口:无法使已实现的方法受到保护或私有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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