Home > Back-end >  Spring how to take the members of the generic type object variable injection?
Spring how to take the members of the generic type object variable injection?

Time:02-11

[size=24 px] [size=13 px] a member variable such as
The @autowired
Private List List1.

Then a Spring components:
@ Component
Public class MyList extends LinkedList {},

After compiling, generic erase, but
MyList object still cannot inject List1;
That Spring will be injected object to member variables and for a generic test,
Member variables of generic I know, can through the Field. The getGenericType (),
But the generic information Spring MyList is how to know?
I guess, at the time of scanning MyList components, to save the generic information to BeanDefinition,
Dependency injection, compare the variables of the generic type object with generics information, inconsistency is an error, but I can't find where there is saved in the BeanDefinition generics information!
Another, use an anonymous inner class, object by a generic class information:
Type genericSuperclass=new MyList) ({}) getClass () getGenericSuperclass ();
ParameterizedType pt=(ParameterizedType genericSuperclass);
Type Type=pt. GetActualTypeArguments () [0];
But there is a problem, is an anonymous inner class can only be written in the source code, can be dynamically generated when program is running?
Or any other way, the Spring is how to determine whether a generic around?
[/size] [/size]

CodePudding user response:

Used mybatis plus ah...
  • Related