Yes, any class can be used as Map Key as long as the following points are considered:
The class overriding the equals() method must also override the hashCode() method
The class should adhere to the rules associated with equals() and hashCode() for all instances
The class field which is not used in the equals() method should not be used in hashCode() method as well
The best way to use a user-defined key class is by making it immutable. It helps in caching the hashCode() value for better performance. Also if the class is made immutable it will ensure that the hashCode() and equals() are not changing in the future.