Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove Spring CrudRepository unchecked conversion beside using suppress annotation

This is my code :

public interface UserRepo extends CrudRepository<User, Long> {

    boolean exist(Long id);

    @Override
    User save(User user);

}

In eclipse, there is a warning on the return type User.

Description Resource Path Location Type Type safety: The return type User for save(User) from the type UserRepo needs unchecked conversion to conform to S from the type CrudRepository UserRepo.java

May I know

  1. what is the reason ecplise warning on return type unchecked conversion?
  2. what is the correct way to get rid of the warning?

TQ

like image 271
user3832050 Avatar asked Oct 18 '22 18:10

user3832050


1 Answers

As @dunny figured out in his comment, this statement makes no sense in the interface, as it is already implemented in org.springframework.data.repository.CrudRepository.save(S)

Eclipse gives this warning as it can not know, that the S in the super implementation is a User in this case.

In order to answer your 2. question, you can do a

@Override
<S extends User> S save(S user);

Then you get rid of the warning, but even then, it does not make more sense to provide this signature.

Just skip this statement, as it is already there.

like image 100
davey Avatar answered Oct 21 '22 01:10

davey