为什么子包看不到包私有类?

编程入门 行业动态 更新时间:2024-10-25 08:26:33
本文介绍了为什么子包看不到包私有类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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 ++/中处理此标准(因为我是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++/ (as I am a java guy :) )

更多推荐

为什么子包看不到包私有类?

本文发布于:2023-10-16 05:23:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496628.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!