How can i allow the user to use class specific methods in generic class T?

15 hours ago 2
ARTICLE AD BOX

I am making a custom LinkedList<T> in java, as a way to learn more about data structures, and i am trying to make a search method, that filters items based on the input, but i ran into an issue, Classes other than primitive types require the use of their own dedicated methods to compare them, such as a .getGrade() on a Student, how could i accommodate for such in my code?

Attached is current search method that does not compare content inside classes:

public CustomLinkedList<CustomNode<T>> search(T data){ CustomLinkedList<CustomNode<T>> result = new CustomLinkedList<>(); CustomNode<T> currentNode = headNode; if(currentNode.value() == data) result.insert(currentNode); while(currentNode.next() != null){ currentNode = currentNode.next(); if(currentNode.value() == data) result.insert(currentNode); } return result; }
Read Entire Article