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
Return type is not taken into consideration when overloading, so essentially you can't really do that. I would simply rename my implementation.
You can't do it, the return type can't be the only difference between two otherwise identical Java method signatures.
The easiest way to fix it is to declare User as a field instead of extending it:
public class MyUserDetails implements UserDetails {
private final User user;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With