Search code examples
javamethodsextendsimplements

Implementing a method that is also overriden


I am adding spring-security into my app and came across an issue. My implementation of UserDetails implements org.springframework.security.core.userdetails.UserDetails but also extends my User entity class. Both of these have a getPassword() method, the spring security interface's method returns a String and mine returns a byte array since the password is encrypted.

I want my implementation to implement the interface's method and not override my entity class' method but Netbeans keeps giving an error that the return type is invalid. I would like to avoid renaming my getPassword() method to work around this problem.

Is there a way of telling the compiler to implement the interface's method instead of overriding the superclass?

Thanks


Solution

  • Return type is not taken into consideration when overloading, so essentially you can't really do that. I would simply rename my implementation.