I am working with an abstract class and two concrete ones, which implementing the abstract one. The diagram is as the next:

My classes looks as:
abstract class NavItem() {
var attributes: String = ""
var text = ""
}
class NavMenu(val items: MutableList<NavItem>) : NavItem()
class NavLink(var shortText: String) : NavItem()
The problem is when I try to work with the items which could be NavMenu or NavLinks, the NavMenus has a collection of NavLinks.
I am trying to work with the items using polymorphism as the next code:
navMenu.items.forEach{ item ->
buildNavItem(item)
}
the buildNavItem methods seems as:
private fun buildNavItem(navMenu: NavMenu){
navMenu.items
navMenu.attributes
navMenu.items
}
private fun buildNavItem(navItem: NavItem){
navItem.text
navItem.attributes
}
private fun buildNavItem(navLink: NavLink){
navLink.text
navLink.attributes
}
But the code is always getting into buildNavItem(navItem: NavItem), even when in the for each I can see sometimes that the item is NavLink, or is NavMenu.
Any suggestion?
Thanks!!