Yes, offcourse it is legal and question asks only that it is legal or not. But, it is very less efficient as all the elements will be forwarded to only one slot 17. Hence, when there are N elements, all are forwarded to same slot and we have to search the element in this slot, which will be very less efficient.
So, it is always better to use key value to forward a particular element into a particular slot .
This is better =>
public int hashCode(x) {
return (x + 7);
}