I'm struggling to suss something out with Java. How do I use the method giveCode() to return the integer value for an object. This is code that was pre written by our lecturer, and we have to use it to return an integer value for an object, it's to be used when creating hash values for a hash table.
HashCode.java
// Interface for HashCode. Has only one method declaration
public interface HashCode {
// For an input object, computes and returns its HashCode as an integer
public int giveCode(Object o);
}
StringHashCode.java (I created this class as we are supposed to implement the HashCode class into this class)
public abstract class StringHashCode implements HashCode{
}
I've tried things like this in my main, just to simply return the code value, so I can see how it works, but nothing seems to be working:
System.out.println(new StringHashCode.giveCode(example_object));
Or
System.out.println(new StringHashCode.giveCode(example_object.hashCode()));
Or
System.out.print(HashCode.giveCode(example_object));
I'm quite new to Java, but I have a lot of experience with other OOP languages, but I can't seem to grasp the issue with this one, I feel like it's probably something stupid, but I can't suss it out.
new StringHashCode()