TypeCasting in Java for Interface

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

The difference is that, since String and StringBuffer are two classes, there is absolutely no way for a class to extend both StringBuffer and String.

But since Collection and Map are interfaces, it’s perfectly possible for a class to implement both Collection and Map. So the cast is valid: map could be an instance of a class that implements Map and also implements Collection.