Why is ArrayList in Java hashable and List in Python not. It's just based on the choice of the developers or language semantics.
I think Python doesn't allow list to be hashable because it's mutable and hence the hash can change over the lifetime of the object.
It's a good feature or bad feature why does Java allow it.
public class Test {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("hello");
System.out.println(list.hashCode());
}
}
works fine while below doesn't
>>> l = ["hello"]
>>> l.__hash__()
Traceback (most recent call last):
File "<pyshell#103>", line 1, in <module>
l.__hash__()
TypeError: 'NoneType' object is not callable