As Auxi said, use interact method:
InteractableEntity x = ....;
x.interact("some action from object");
Interact method also returns a boolean value, then you can use it in a if block to check if the interaction was properly:
InteractableEntity x = ....;
if (x.interact("any action")){...