I'm new to generics, and am struggling with applying to my situation:
I currently have several SyncData Classes, one for each object type that I wish to sync. I'm looking at changing this to a single generic class SyncData. Within this class some parts of the code will use objects of type T, but I'd also like to reference static Methods of type T. This would enable me for example to specify a notification action (specific to the data type) to be called on completion of the sync.
I'm getting myself caught in a loop: to access the methods I need to define an interface that all the types will implement, in the generic T extends interface, and then I can reference the relevant methods of type T within my generic SyncData Class. However I can't specify a static method in an interface, and because I can't in the interface, I cant access it in my generic SyncData Class.
I've looked at various tutorials, questions here etc, maybe I'm missing the obvious, but I can't see the way forward - everything that comes up seams to refer to different issues with generics and static nethods. Any advice would be very much appreciated.
Edit:
As requested some sample code added to illustrate what I tried to do (I'm actually looking to use static methods at various other points within the code, but this illustrates the point).
Is it possible to access the static method of class T from within the SyncAction class (without making T extend DataType1 by which point there is no point using generics as T cannot be DataType2)?
public interface Syncable {
//following needed or I can't access onSyncComplete in SyncAction
public void onSyncComplete();
}
public class DataType1 implements Syncable {
//constructor etc removed as irrelevant to question
//Eclipse warns 'this static method cannot hide instance method from Syncable'
public static void onSyncComplete(){
//do stiff here
}
}
public class SyncAction<T extends Syncable>{
//do all the syncing etc using multiple DataType1 objects
T.onSyncComplete();
}