Can't get slot index of slot in enderchest

The following code not work:

Inventory enderChest = player.getEnderChestInventory();
for (Inventory slot:enderChest.slots()){
    slot.getInventoryProperty(SlotIndex.class).ifPresent(slotIndex -> {
        System.out.println(slotIndex.getValue());
        //print nothing
    });
}

But this work:

Inventory enderChest = player.getEnderChestInventory();
for (Inventory slot:enderChest.slots()){
    SlotAdapter adapter = ((SlotAdapter) slot);
    System.out.println(adapter.slotNumber); // this work
}