Doubt regarding Generic LinkedList

If we want to make a linked list as generic then instead of writing , can we write ? And if we are able to write to make a data structure as generic , then why should we use ?

No <T> and object both are reserved keywords in the Java language. Creating a linked list of object class will make it inheritable by all classes (as all classes are derived from the object class) thus making the methods accessible to the child classes which have inherited this linked list. Whereas creating a linked list of <T> class will apply these features onto the classes which is a specific implementation of the generic linked list.

As an example, let us say we created a linked list of both object and <T>.
Now the first linked list is a concrete linked list (created in memory) of object data type and thus can be used to store objects.
The second linked list will not be created in memory(only a reference will be present to the linked list) until it has been instantiated using a specific data type like int or double. At this point the linked list gets created in memory of that specific data type.
Now coming to the second part of why we should use <T> over object, the reason is that all the methods declared inside the linked list will be applied on that data type, so if that method is not compatible with the data type it will throw error.
Taking example of this, let us say a method is declared in the linked list as valueOf(object a) for an object linked list. This will throw an error as valueOf method does not exist for object data types.
The same is not true foe valueOf(T a) as it will not get instantiated in memory until done so with a specific data type like IntegerorCharacter, both of which contain the valueOf` method.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.