A
Aryeh M. Friedman
First of all let me say I am aware of type erasure.
Let's say I have something like:
ArrayList<Integer> foo=new ArrayList<Integer>();
is there any way at run time to determine the type parameter is
Integer... more specifically if
I have
public interface MyClass<T>
{
....
}
public class MyClassImpl<T> implements MyClass<T>
{
....
}
public class MockMyClass<T> implements MyClass<T>
{
....
}
public
Is there any way of knowing the value of T at run time.
If the above is not possible maybe there is still a way to accomplish
what I have in mind.... basically if some class does the following:
public class MyApp<T>
{
private ArrayList<T> data;
public MyApp()
{
data=new ArrayList<T>();
}
.....
}
I want to be able to replace T with TImpl (i.e. in the case of MyClass
replace it with an instance of MockMyClass [NOT MyClassImpl]) {this
needs to be done via reflection and not modifing the source code}....
Note I already have something that works for single instances and
arrays but not for collections (thus the need for determing the generic
type)
Let's say I have something like:
ArrayList<Integer> foo=new ArrayList<Integer>();
is there any way at run time to determine the type parameter is
Integer... more specifically if
I have
public interface MyClass<T>
{
....
}
public class MyClassImpl<T> implements MyClass<T>
{
....
}
public class MockMyClass<T> implements MyClass<T>
{
....
}
public
Is there any way of knowing the value of T at run time.
If the above is not possible maybe there is still a way to accomplish
what I have in mind.... basically if some class does the following:
public class MyApp<T>
{
private ArrayList<T> data;
public MyApp()
{
data=new ArrayList<T>();
}
.....
}
I want to be able to replace T with TImpl (i.e. in the case of MyClass
replace it with an instance of MockMyClass [NOT MyClassImpl]) {this
needs to be done via reflection and not modifing the source code}....
Note I already have something that works for single instances and
arrays but not for collections (thus the need for determing the generic
type)