Student class has roll number, standard, first name and last name. And LinkedHashMap class has the key as student object and value as an integer. My question is why is the Student object giving error of compile time as cannot make static reference to a non static type Student. I have made all the attributes in STudent class as static. And error - LinkedHashMap is a raw type. References to generic type LinkedHashMap<Student,Integer> should be
parameterized
Jeanne Boyarsky
,
author & internet detective
staff
Multiple markers at this line
- The type LinkedHashMap is not generic; it cannot be parameterized with arguments <Student,
Integer>
- Cannot make a static reference to the non-static type Student
- Cannot make a static reference to the non-static type Integer
You named your LinkedHashMap class after another that already exists. Don't reuse names from the standard API.
You're probably trying to use java.util.LinkedHashMap (which is generic), but the compiler thinks you want to use the class you declared (which is not generic).
@ Stephan thanks. But again an error - All the outputs are the same .
roll no=2 standard=6 firstname=Kajari lastname=Agrawal 2
roll no=2 standard=6 firstname=Kajari lastname=Agrawal 4
roll no=2 standard=6 firstname=Kajari lastname=Agrawal 6
roll no=2 standard=6 firstname=Kajari lastname=Agrawal 5
roll no=2 standard=6 firstname=Kajari lastname=Agrawal 7
Jeanne Boyarsky
,
author & internet detective
staff
When designing hashCode() and equals() you need to take into account which fields you'll want to use. I'm assuming in your case that firstname and lastname together make up a unique key for each object, and that rollno and std are not unique or don't add any additional uniqueness to firstname and lastname. If that's the case then you might only want to use firstname and lastname when you create hashCode() and equals().
Jeanne Boyarsky
,
author & internet detective
staff