Skip to content
Advertisement

Why do I get an error when entering child classes to a TreeMap defined for their parent? [closed]

In my program I have an abstract class TelephoneEntry which holds a TelephoneNumber(it implements Comparable) and an addres, then I have child classes Person and Company that extend the TelephoneEntry class.

JavaScript

But when I try passing them to a tree map defined as

JavaScript

I get an error stating that:

JavaScript

I’m not sure what may the cause of this error be as they both inherit the used key from TelephoneEntity.

Advertisement

Answer

Maps have put() method, not an add() method, for adding entries.

Change your code to:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement