'Not understanding why I can call interface methods without concrete implementation

I am working on a Spring Boot application which uses Spring Data Jpa. I cannot give you the exact code since I am not allowed to, but I can simplify my issue so you may get an idea:

@Query("SELECT u FROM User WHERE u.uuid = :#{#uuid}")
Optional<UserInterface> findProjectedUserByUuid(UUID uuid)

This Query return an interface of type UserInterface:

public interface UserInterface{
    String getName();
    String getEmail();
}

Somewhere in my service class I get to this point:

UserInterface userInterface = userRepository.findProjectedUserByUuid(uuid).get();

System.out.println(userInterface.getName());

The application correctly prints out the name of the user.

My question is: why can I call userInterface.getName() in the code and return the correct name. Isn't this supposed to be an interface? How is it holding data?

My guess is...but I am not really sure about this, hence why I am asking you guys, this is a case of polymorphism. I believe that the repository is actually returning a class which implements my interface? And maybe that is why I am able to call methods on it. But if this is true, is there any way to see which class gets returned or use it in any meaningful way?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source