A subtype is established when a class is linked by means of extending or implementing. Subtypes are also used for generics.
How can I differentiate subtyping from subclasses?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Java, subclassing is a kind of subtyping.
There are a number of ways Java allows subtyping:
class A extends B,Ais a subtype ofBbecauseB b = new A(...);is ok.interface A extends B,Ais a subtype ofBbecauseB b = new A() { ... }is ok.class A extends B,A[]is a subtype ofB[]becauseB[] b = new A[0]is ok.class A implements B,Ais a subtype ofBbecauseB b = new A(...)is ok.It sounds like you want a way to distinguish one from the others. The below should do that.
It won’t handle subtyping of generic classes due to type erasure though.
Classinstances don’t carry type parameters at runtime so there is no way to distinguish the runtime type of anew ArrayList<String>()from anew ArrayList<Integer>().