M
M
multiscripter2018-07-21 14:00:41
Java
multiscripter, 2018-07-21 14:00:41

How to get generic bean without unchecked?

Hello everybody.
There is some class with parameterized type Storage<T>.
All three statements below result in a warning. unchecked cast.
Storage<User> storage = ctx.getBean("storageMemory");
Storage<User> storage = ctx.getBean(Storage.class);
Storage<User> storage = ctx.getBean("storageMemory", Storage.class);
Actually the question is:
How to get a bean of a generic type without uncecked? Annotations or xml - doesn't matter.
Is there any option other than making storage a field of some autowired container class?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cr2ed, 2018-07-25
@Cr2ed

And why, for example, do not make heirs of the type

@Repository
public class UserStorage extends Storage<User> {
    ...
}

and work directly with them?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question