0

If I have a interface that has a type parameter , and an implementation of that interface like so:


public interface BaseService<T> {
    List<T> getAll();
    Optional<T> findById(long id);
    T save(T user);
    void delete(long id);
}

@Service
public class UserService implements BaseService<User> {

Is it possible at all to do something like this?

class BaseThingController<T> {
    @Autowired
    private BaseService<T> service;

ATM it tells me a bean cannot be found with that, just wondering if theres a way to make this work

Aj3douglas
  • 51
  • 1
  • 7
  • hm, Im tryna achieve full abstraction here, whats the closest i could probably get to this? – Aj3douglas Oct 11 '20 at 11:51
  • BaseThingController isnt actually annotated with @Controller, its subclasses are tho, for example a subclass of BaseThingController would be like class Thing extends BaseThingController – Aj3douglas Oct 11 '20 at 11:55
  • I need to be able to access the service in the parent – Aj3douglas Oct 11 '20 at 11:57

0 Answers0