How to get common Subclasses of 2 Interfaces in Java with Eclipse?

Actually I try to find a subclass of InputStream which is also Serializable. I think that doesn't exist. Since both Interfaces have many sublclasses it is hard to find one that is a subclass of both.

Until now I haven't found anything to help my search in Eclipse. Anyone ideas?

Edit: I understand now that serializing a Stream isn't really what one should do. But the essence of the Question is: how can I find a common subclass of two Interfaces.

Asked by: Thomas401 | Posted: 28-01-2022

Answer 1

Serializing an InputStream is not a very viable solution. To illustrate this, imagine if you have an InputStream from a socket and you serialize that. Before you deserialize it, the socket is closed. Now when you actually do deserialize it, the resource has vanished and you have a nasty exception in your hands.

What you should rather do, if you need to serialize a resource, is to serialize the location of it or how to obtain it. In the socket example: host name and port, for files: the file path, etc.

Answered by: Adelaide664 | Posted: 01-03-2022

Answer 2

In eclipse the key shortcut Ctrl+T opens the type hierarchy. You can even use this feature on a base class or an interface an you get a list with all implementation/subclasses of this type.

If you do this twice and compare the two results you will find your classes. However in case of e.g. Serializable and Comparable the intersection may become quite huge ...

Answered by: Jack464 | Posted: 01-03-2022

Answer 3

Don't be offended, but it sounds to me like you're attempting to solve the wrong problem. What are you really trying to achieve?

Answered by: Dominik472 | Posted: 01-03-2022

Answer 4

I am not sure that you can do that in fact (or at least in an easy way...).

Anyway, I like the "Open Implementation" plugin that allows you to right-click on a method of a class or an interface (or the class / interface itself) and ask for all known implementation of this method / interface / class. This plugin may help you (you can now search for all implementation of the InputStream

Answered by: Marcus497 | Posted: 01-03-2022

Answer 5

You can get a set of subtypes programmatically with the Reflections library. Intersection of two sets will be your answer.

Set<Class<? extends Serializable>> subTypes = 

However, this isn't an Eclipse specific solution.

Answered by: Chelsea622 | Posted: 01-03-2022

Similar questions

java - Subclasses that inherit generic interfaces

I have an interface that ensures objects can make copies of themselves: public interface Duplicable&lt;T extends Duplicable&lt;T&gt;&gt; { public T duplicate(); } I now have class X implements Duplicable&lt;X&gt; but I also have a class Y that extends X. This isn't a problem, until I need another generic class: public class D...

Why doesn't Java allow generic subclasses of Throwable?

According to the Java Language Sepecification, 3rd edition: It is a compile-time error if a generic class is a direct or indirect subclass of Throwable. I wish to understand why this decision has been...

Java access modifiers - method available to subclasses and package

Which access modifiers which when used with the method makes it available to all the class and subclasses within a package?

java - List all subclasses with fully qualified names

I would like to get a list of all subclasses of a given class with their fully qualified names. I wanted to copy it from Eclipse and paste into a text file like this: some.package.Class1 some.package.Class2 some.other.package.Class3 ... I've tried: doing Search | Java | Type, Limit to implementors. But this one for some strange reasons doesn'...

java - Subclasses of a class that implements a generic interface

I'm working with Google Web Toolkit, and I'm having problems implementing a generic interface. I'm not really familiar with generics, doing an upgrade on someone else's code here. Here's what I want to do: I want to have an implementation of a generic callback interface that does some logging, and then subclass that implementation in order to handle specific callback scenarios. The interface is something li...

Java - abstract class, equals(), and two subclasses

I have an abstract class named Xpto and two subclasses that extend it named Person and Car. I have also a class named Test with main() and a method foo() that verifies if two persons or cars (or any object of a class that extends Xpto) are equals. Thus, I redefined equals() in both Person and Car classes. Two persons are e...

java - Best practice for class field having different values in subclasses

I have some abstract class, in one of its method I use a string field which is supposed to be specific to the subclasses. I wonder what is the bect practice to implemnet this? via field and setting the field value in a consructors of the subclasses? via a static field and changing the value in every subclass? What would you suggest?

java - HIbernate loads subclasses along with classes

I am using Hibernate to connect to my database. I have an inheritance structure in my application.The problem is that when i do a query like "from Animal", it does a left outer join for the class Animal,its sub classes and all the associations for Animal and its subclasses. How do i avoid this situation.I want to load the data only when i specify it through a fetchmode in my criteria query?

java - Design pattern to handle settings in subclasses?

I have a small hierarchy of classes that all implement a common interface. Each of the concrete class needs to receive a settings structure containing for instance only public fields. The problem is that the setting structure has a part common to all classes has another part that vary from one concrete class to another I was wondering if you had in your mind any elegant design to ...

java - Casting subclasses extending the same original class

How can I cast two extends class like that in java? class B extends Object{ } class C extends Object{ } B b = new B(); C c = (C)b;//Cannot cast from B to C

java - How to show all parents and subclasses of a class in IntelliJ IDEA?

When I'm editing a Java class in Eclipse, when my cursor is over a class variable, I can do Ctrl+T to have a popup that shows all its parents and subclasses. What is the equivalent in IntelliJ? Example: Use|r user = new User(); The pipe is my cursor.

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)