I try to make the generic method for other class. But I got a error cannot be referenced from a static context
How to do the generics method for GetInstance
public class Instance<T> {
private static final Instance<?> mInstance = new Instance<>(null);
@SuppressWarnings("unchecked")
public static Instance<T> GetInstance() { //Got error
// Make generic static instance.
// Strategy used similar to Collections.emptyList() implementation
return (Instance<T>) mInstance; //Got Error
}
protected Instance(Context context) {
}
}
public static DataController GetDataController(@Nullable Context context) {
DataController dataController = (DataController) DataController.GetInstance();
if(dataController == null) {
return new DataController(context);
}
return dataController;
}