首页 \ 问答 \ 在Java中访问每个父类的子类(Accessing every child class of parent class in Java)

在Java中访问每个父类的子类(Accessing every child class of parent class in Java)

我必须实现一个给定子类的逻辑,我需要访问它的父类以及该父类的所有其他子类(如果有的话)。 我没有在Java Reflection中找到任何API,它允许我们访问父类的所有子类。 有什么办法可以做到吗?

例如:

class B extends class A
class C extends class A

现在使用类B,我可以通过调用getSuperClass()来找到超类。 但有没有办法找到所有的子类,一旦我有父类,即B类和C类?


I have to implement a logic whereby given a child class, I need to access its parent class and all other child class of that parent class, if any. I did not find any API in Java Reflection which allows us to access all child classes of a parent class. Is there any way to do it?

For example:

class B extends class A
class C extends class A

Now using class B, I can find the superclass by calling getSuperClass(). But is there any way to find all the child classes once I have the parent class i.e. class B and class C??


原文:https://stackoverflow.com/questions/2695349
更新时间:2021-09-28 13:09

最满意答案

实际上, 在应用程序级别寻找东西是唯一的方法 。 以下是一些问题:

  • 当您send数据时,即使它离开您的内核,在TCP收到有关它的ACK之前,它也不会完成。 API不会向您提供此信息

  • 您的应用程序收到ACK的事实可能意味着:

    • 远程内核( 不是应用程序 )接收数据。 没有人知道远程进程是否称为recv 。 也许它在有机会重新开始之前就崩溃了。
    • 一些代理(许多廉价设备这样做)正在与您交谈,并且使用与真实接收器的单独连接。 您收到了ACK但是您不知道远程系统是否有它。 如果远程系统有它,请阅读上面的子弹。

结论是:

  • 您无权访问TCP ACK
  • 即使你会对他们有所帮助,他们也会毫无用处

所以你需要一个应用程序级别的ACK,但当然没有重传ACK应该只告诉您“我收到并处理了您的数据”。

编辑

我看到你坚持你的想法。 如一些Linux手册页所述,去寻找SIOCOUTQ 。 当然它只是Linux,但看看它是否能满足您的需求。


Actually acking stuff at application level is the only way. Here are a few issues:

  • When you send data, even if it leaves your kernel it's not done until your TCP receives an ACK about it. The API doesn't provide you with this information.

  • The fact that your application received an ACK can mean:

    • The remote kernel (not the application) received the data. There's no telling if the remote process called recv. Maybe it crashes before getting a chance to recv.
    • Some proxy (MANY cheap devices do this) is talking to you and is using a separate connection with the true receiver. You received the ACK but you don't know if the remote system has it. And if the remote system has it, read the bullet above.

In conclusion:

  • You don't have access to TCP ACKs
  • Even if you would have acess to them, they would be useless

So you need an application-level ACK, but of course without retransmissions. The ACK should merely tell you "I received and processed your data".

EDIT

I see you persevere in your idea. Go look for SIOCOUTQ as described in a few Linux manual pages. Of course it's Linux-onlye, but see if it does what you need.

相关问答

更多
  • 实际上, 在应用程序级别寻找东西是唯一的方法 。 以下是一些问题: 当您send数据时,即使它离开您的内核,在TCP收到有关它的ACK之前,它也不会完成。 API不会向您提供此信息 。 您的应用程序收到ACK的事实可能意味着: 远程内核( 不是应用程序 )接收数据。 没有人知道远程进程是否称为recv 。 也许它在有机会重新开始之前就崩溃了。 一些代理(许多廉价设备这样做)正在与您交谈,并且使用与真实接收器的单独连接。 您收到了ACK但是您不知道远程系统是否有它。 如果远程系统有它,请阅读上面的子弹。 结论 ...
  • 仔细看看boost::asio 。 异步IO是它的专长(顾名思义。)它是非常成熟的库,现在从1.35开始在Boost中 。 许多人在生产中使用它来进行非常密集的网络。 文档中有大量示例 。 有一件事是肯定的 - 它非常重视缓冲区 。 编辑: 处理突发输入的基本思想是排队 。 比如创建三个预先分配的缓冲区链表 - 一个用于空闲缓冲区,一个用于待处理 (接收)数据,一个用于待发送数据。 每次你需要发送一些东西 - 从空闲列表中取一个缓冲区(如果空闲列表为空,则分配一个缓冲区),填充数据,将其放入待发送列表中。 ...
  • 响应从哪里获取数据,从操作系统缓存或直接从网站获取数据? 我还没有学习操作系统,这使我很难综合缓冲过程。 从网络设备(以太网卡,Wi-Fi适配器等)接收TCP数据包,并将其有效负载数据放入TCP / IP堆栈内的临时缓冲区中。 当你的程序调用recv() ,这些数据的一部分或全部从临时缓冲区复制到你的程序缓冲区( response )中。 TCP / IP协议栈除了上述内容之外不会执行任何数据缓存。 (例如,如果网络浏览器想要缓存网页的本地副本,以便它不必再次下载它,则将取决于网络浏览器本身在应用程序级别执 ...
  • 是的,这是唯一的方法。 使用TCP的全部原因是它是一个“可靠”的协议,保证交付。 与UDP相反。 TCP的工作是按发送顺序将数据传送到接收器,而不会丢失任何内容。 如果无法传递数据,那么在TCP放弃的某个时刻连接会中断。 但是,只要有活动连接,接收方就会获得发送方发送的所有内容。 如果您不想获得发件人获得的某些数据,您必须与发件人做出任何适当的安排,以便实现这一点。 TCP不会丢弃数据,只是因为接收者不想要它。 Yes, it's the only way to do it. The whole reaso ...
  • MQTT-S可以在UDP上运行,但是还没有任何公开可用的库。 你确定电池使用量是个大问题吗? 在http://stephendnicholas.com/archives/219上对Android上的MQTT电源使用进行了一些实验。 我认为MQTT本身确实利用了TCP交付和订购保证。 我相信要保证它在UDP上运行是非常困难的。 MQTT-S can run over UDP, but there aren't any publicly available libraries for it yet. Are y ...
  • 除非您是TCP / IP专家并了解其全部后果,否则不要设置NoDelay 。 如果你还没有读过史蒂文斯,那就别想了。 这是一个示例问题:如果您建立套接字连接并在其上发送8个字节,是否立即发送8个字节或Nagle算法是否等待发送更多数据? 答案是“立即发送8个字节” - 但是在你明白为什么这是答案之前不要考虑搞乱Nagle。 这是另一个问题:在标准命令/响应协议中,每个数据包应用了多少Nagle延迟? 答案是:没有。 同样,您应该研究为什么 Nagle在这种常见情况下不会造成任何延迟。 如果您没有看到250毫 ...
  • 即使缓冲区尚未填充,您也调用bytesRead < count (如果bytesRead < count )。 考虑切换到await应用程序的异步部分。 这摆脱了可怕的回调递归。 You're calling OnMessageReceived even if the buffer has not been filled (in case bytesRead < count). Consider switching to await for the async part of the application ...
  • 我们决定在客户端之间以及客户端和服务器之间添加另一种类型的消息来检查连接状态。 我们将使用1秒计时器从一个客户端向另一个客户端发送消息,如果客户端没有收到超过3秒的消息,他们将认为连接被中断并将向服务器发送消息,以检查是否连接与服务器是可以的[只是让用户知道问题存在的地方]。 We have decided to add another type of messages to be sent between clients and between client and server to check the ...
  • 它还取决于接收器窗口大小。 即使有100个标题,发送方也会根据接收方可用的窗口大小来推送数据。 没有启用扩展的TCP窗口大小最多只能达到64kb。 在您的情况下,这个大小是不够的,因为它至少需要(100-183Mbits)10MB缓冲区。 在Windows 7和更新的Linux OS中,TCP默认启用窗口缩放,可以将大小扩展到1GB。 启用TCP窗口缩放选项后,您可以将套接字缓冲区增加到更大的大小,例如50MB,这应该提供所需的缓冲。 It also depends on the receiver wind ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)