I have the below function:
public void putList(String key, List lst){
if (T instanceof String) {
// Do something
It is not possible to determine this due to erasure, which means that the parameter is not stored in the code. However you can either pass an extra parameter specifying what type the list is:
public void putList(String key, List lst, Class listElementType) {
}
or you can determine the type of each element at runtime:
public void putList(String key, List lst){
for (Object elem:lst) {
if (elem instanceof String) {
// Do something
}
if (elem instanceof Integer) {
// Do something
}
}
}