I am new to java and coming form c++ background. i have encountered a problem while making a generic class with comparable interface. In the SearchByID and SerchByName methods of LinkedList class it gives error on temp.value.getID() and temp.value.getName(), i am making an object of Linkedlist class in main so , according to my understanding temp.value should give me an employee object for which i am calling getID which is a function of Employee class . but still it gives me this error . is there anything i understood incorrectly ? or making a mistake in this code .
cannot find symbol symbol: method getID()
public class Employee implements Comparable<Employee>
{
private int empID;
private String name;
private int salary;
private boolean manager;
private int subordinates;
public Employee()
{
empID = 0;
name = "";
salary = 0;
manager = false;
subordinates = 0;
}
public Employee(int id , String name , int salary , boolean manager , int sub)
{
empID = id;
this.name = name;
this.salary = salary;
this.manager = manager;
subordinates = sub;
}
public int getID()
{
return this.empID;
}
public String getName()
{
return this.name;
}
@Override
public int compareTo(Employee other)
{
if (this.empID < other.empID)
{
return -1;
}
else if (this.empID > other.empID)
{
return 1;
}
else
{
return 0;
}
}
and this is my Linkedlist class
public class LinkedList<T extends Comparable<T>>
{
private int count;
private Node<T> head;
//completely encapsulated Node class from outer world as they dont need it
private class Node<T>
{
public T value;
public Node<T> next;
public Node(T data)
{
this.value = data;
this.next = null;
}
}
LinkedList()
{
count = 0;
head = null;
}
public Node<T> SearchByID(int id)
{
Node<T> temp ;
for (temp = head; temp.value.getID() != id; temp = temp.next);
return temp;
}
public Node<T> SearchByname(String name)
{
Node<T> temp ;
for (temp = head; temp.value.getName() != name; temp = temp.next);
return temp;
}