Covariant Method Overriding in Java — The Hidden Feature That Saves You from Casting
Why This Little-Known Java Feature Makes Your Overridden Methods Smarter
Sometimes, knowing a small but powerful Java feature can dramatically improve your code quality. Covariant method overriding is one of those hidden gems.
Introduced in Java 5, covariant return types let you override a method and return a more specific type than the one declared in the superclass.
Keep reading with a 7-day free trial
Subscribe to Javarevisited Newsletter to keep reading this post and get 7 days of free access to the full post archives.

