I am working on a Java application in which I found this class:
public class TipologiaGenerica<K> {
private K codice;
private String descrizione;
public TipologiaGenerica(K codice, String descrizione) {
this.codice = codice;
this.descrizione = descrizione;
}
public K getCodice() {
return codice;
}
public void setCodice(K codice) {
this.codice = codice;
}
public String getDescrizione() {
return descrizione;
}
public void setDescrizione(String descrizione) {
this.descrizione = descrizione;
}
}
As you can see this class is declared as: TipologiaGenerica and K seems to be something like an object type that could be passed when a specific TipologiaGenerica object is created and that determinate the type of one of its inner field, this one:
private K codice;
Infact, somewhere else in the code, I find a TipologiaGenerica object creation:
TipologiaGenerica<String> dataPerLista = new TipologiaGenerica<String>(dataString, dataString);
What exatly mean? I think that doing in this way it is creating a specific TipologiaGenerica object having the inner codice field that is a String.
Is it my reasoning correct? What is the name of this specific use of Java? What are the most common purpose of this type of constructor?