user1604294 :
I have this compilation problem:
Here is the class in question:
package huru.entity;
import io.vertx.core.json.JsonObject;
import java.util.Date;
public class BaseEntity <T extends BaseModel> extends JsonObject {
private T model;
public BaseEntity(T m){
this.model = m;
}
public void setUpdateInfo(String user){
this.model.updatedBy = user;
this.model.updatedAt = new Date();
}
public JsonObject toJsonObject(){
return JsonObject.mapFrom(this.model);
}
public T getEntityType (){
return this.model.getClass(); // doesn't compile
}
}
I also tried using
public T getEntityType (){
return T; // doesn't compile
}
but that clearly doesn't work either. Anybody know how I can return the class instance of that generic type?
I also tried this:
public Class<T> getEntityType (){
return this.model.getClass();
}
and I get:
and then I tried this:
public Class<? extends T> getEntityType (){
return this.model.getClass();
}
and I have:
Vinay Avasthi :
What about the following code. I think it works.
public Class<? extends BaseModel> getEntityType (){
return model.getClass();
}