Whenever you create a subclass in Java you can override the inherited methods. You can even vary the the return types. But you are limited when doing so, because your subclass will have to satisfy the Liskov Substitution Principle (LSP). In this blog post I will discuss in which respect you are allowed to change the return type.
C# 4.0 introduced the dynamic keyword that allows you to store instances of whatever type you want into it. And the language allows you to use the variable in whatever context you want. As the name of the keyword suggests, the problems will haunt you at runtime.
By design Java and C++ only offer single dispatch on method calls. Meaning that the dispatch is only based on the dynamic data type of the receiver. This becomes a problem if you want to have different method implementation based on the dynamic type of the argument and the receiver. In this post I am going to show how you circumvent the limitation using the double dispatch technique in Java. One of the more apparent usages of the double dispatch is in the famous Visitor Pattern. The discussion will then lead to the Expression Problem.
I am often surprised to see how many programmers do not understand overloading and overriding concepts. In my opinion these are two key concepts of object-oriented programming every OO programmer should know in its basics.