Skip to content
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

Open
SHAMSRIZWAN opened this issue Oct 20, 2021 · 2 comments
Open

clarification on Integer class Hierarchy #108

SHAMSRIZWAN opened this issue Oct 20, 2021 · 2 comments

Comments

@SHAMSRIZWAN
Copy link

No description provided.

@SHAMSRIZWAN SHAMSRIZWAN changed the title clarification on Integer class Hierarchy its written in the Generics section that clarification on Integer class Hierarchy Oct 20, 2021
@SHAMSRIZWAN
Copy link
Author

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 ,
And thanks for collecting all the resources ,

@MalaRuparel2023
Copy link

Generics in Java:
Generics in Java provide a way to create classes, interfaces, and methods that operate on objects of specified types. They allow you to parameterize the types used in your code. For example, List is a generic type where T is the type parameter representing the type of elements in the list.

Inheritance in Java:
Inheritance is a fundamental concept in object-oriented programming where a class can inherit fields and methods from another class. In Java, every class (except for Object) has exactly one direct superclass (single inheritance).

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<>();
integerList.add(10);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants