-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
clarification on Integer class Hierarchy #108
Comments
Hi, its written ,-> It should be noted that standard class hierarchy does not apply to generic types. It means that Integer in List is not inherited from - it is actually inherited directly from but when see the class hierarchy it clearly extending The Number class can you eloborate on this , |
Generics in Java: Inheritance in Java: Now, let's address the statement you provided: "It should be noted that standard class hierarchy does not apply to generic types." This statement might refer to the fact that when you have a generic type, such as List, the type List itself is not part of the class hierarchy in the same way as non-generic classes. For example, List is not a subclass of List. Instead, it's a separate type that is parameterized with Integer. However, the elements contained within a List are indeed instances of Integer, which does inherit from Number. So, when you see List, it doesn't directly inherit from List in the class hierarchy, but it does contain elements of type Integer, which does inherit from Number. Here's a simple example to illustrate this: List integerList = new ArrayList<>(); Integer value = integerList.get(0); // value is of type Integer, which inherits from Number In this example, List is not inheriting from List, but the elements it contains (Integer) do inherit from Number. |
No description provided.
The text was updated successfully, but these errors were encountered: