What really is the difference in the way that Java and Python implement type checking?
And what about how they implement abstract data types?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Java does.
Python does not.
Python is strongly dynamically typed. You create an object, and it will always be of that type. However, the variable that points to that object, can be pointed to any object of any type, and doesn’t have to know what type of object it points at.
Edit based on questions in the comments:
This allows you to define a class that can be used by most functions that expect a dictionary, or a list, or another type, very easily. So If I want to create a special kind of list, that when you iterate over it, returns the objects in a custom order, all I have to do is declare a class that supports
__getitem__,__iter__, and a few other methods, and other classes will use it just as if it were a list.For information on abstract base classes in Python, see http://docs.python.org/glossary.html#term-abstract-base-class. In use, they are quite similar to abstract base classes in Java.