jeudi 9 juillet 2020

Making decision based on generic type in java

I have a generic class which has a method getOutput. I want to make decision based on the type of T (the class type). I tried the below but it does not work.

class Test<T> implements Interface1<T> {

public T getOutput(String input) {
    
     if (T instanceof Class1) {
       //do something
     } else {
       //do something else
     }
}

}

Aucun commentaire:

Enregistrer un commentaire