为什么子包看不到包私有类? [英] Why can't sub-packages see package private classes?

查看:98
本文介绍了为什么子包看不到包私有类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有这个项目结构:

Okay so, I have this project structure:

A.B包

  • class SuperClass(此类标记为包私有)
  • class SuperClass (this class is marked package private)

A.B.C包

  • class SubClass(继承自超类)
  • class SubClass (inherits from super class)

我不想让SuperClass公开可见……它实际上只是该特定项目(A.B)的实用程序类.

I'd rather not make SuperClass publicly visible... It is really just a utility class for this specific project (A.B).

在我看来,子类应该可以看到SuperClass,因为A.B.C包是A.B的子包...但事实并非如此.

It seems to me that SubClass should be able to see SuperClass, because package A.B.C is a subpackage of A.B... but this is not the case.

解决此问题的最佳方法是什么?我认为将A.B.C中的所有内容上移到A.B或将A.B上移到A.B.C ...都是没有意义的...主要是因为A.B.D也可能继承自A.B中的内容...

What would be the best way to resolve this issue? I don't think it makes sense to move everything in A.B.C up to A.B or move A.B down to A.B.C... mainly because there will probably be an A.B.D which inherits from stuff in A.B as well...

我对Java有点陌生,所以要好:D(我是C ++和.NET专家)

I'm a bit new to Java, so be nice :D (I'm a C++ and .NET guy)

推荐答案

包是唯一的标识符.您不能使它们遵循继承规则. Package和SubPackages与Super和Sub类不是类似的.

Packages are unique identifiers. You cannot make them follow the inheritance rules. Package and SubPackages are not analogical to Super and Sub classes.

在使您希望在子包中使用的类对外界可见的过程中,我看不到任何缺陷.我想知道如何在C ++/.net中处理此标准(因为我是Java人:))

I dont see any flaws in making the class that you wanted to use in the sub package to be visible to the outside world. I would be interested to know how this criterion is handled in C++/.net (as I am a java guy :) )

这篇关于为什么子包看不到包私有类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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