 methods with generics in java

Ok so I know that you can't have an abstract static method, although I see this as a limitation personally. I also know that overriding static methods is useless because when I am dealing with say MyList<T extends ObjectWithId> and my object has an abstract class with a static method that gets overridden in it's subclasses, T doesn't exist at runtime so ObjectWithId's static method would be called instead of the subclass.
So here is what I have:
class PersistentList<T extends ObjectWithId> implements List<T>{

}

where ObjectWithId is:
abstract ObjectWithId{
    public abstract long getId();
}

Now the issue is that my PersistentList is meant to be stored on hard disk, hence the name, and in reality will only store ids of objects it holds. Now when I want to implement the 
@Override
public T get(int index) {

}

method of PersistentList, what I want is for my program to use the id it has stored for index and call a static method objectForId(long id) which would be implemented in each subclass of ObjectWithId. It can't be a instance method because there is no instance yet, the point is to load the instance from the hard disk using the id. So how should it be implemented? One option is to have ObjectWithId have a constructor ObjectWithId(long id) implemented in each subclass, but T doesn't exist at runtime so how would I instantiate it? I know I could pass Class<T> object in the constructor of PersistentList but I would prefer if the constructor did not have any arguments, but I don't think there is a way to get the class of T without explicitly passing it in right?
I hope this is a better explanation, sorry for the ambiguous question I started with.

A:

While passing the Class<T> as a constructor argument, it does not really solves your problem. You then have access to the class, but to get access to the static method defined on the class you will have to use generics (unless somebody else knows a way to call a static method defined on a class from a Class object).
I would define a new generic interface which contains a generic method objectForID, something like
public interface ObjectRetriever<T>{
  public T objectForID(
methods with generics in java 

 Ok so I know that you can't get an abstract inactive method, although I see this as a limitation personally. I besides know that overriding static method is useless because when I am dealing with say MyList < T extends ObjectWithId > and my aim have an abstract course with a static method that get overridden in it's subclasses, T doesn't exist at runtime so ObjectWithId's static method acting would be called instead of the subclass. 
 So here is what I own: 
 class PersistentList < T extends ObjectWithId > implement List < T > { 

 } 

 where ObjectWithId is: 
 abstract ObjectWithId { 
     public abstract retentive getId (); 
 } 

 Now the issue is that my PersistentList is meant to be stored on hard phonograph record, hence the name, and in reality will only store ids of objects it holds. Now when I want to implement the 
 @Override 
 public T get(int index) { 

 } 

 method of PersistentList, what I want is for my program to use the i d it has stored for index and call a inactive method objectForId(long i d) which would be implemented in each subclass of ObjectWithId. It can't be a example method acting because there be no instance yet, the distributor point is to load the instance from the hard disk using the i d. therefore how should it be implemented? One option is to have ObjectWithId have a constructor ObjectWithId(long i d) implemented in each subclass, but metric ton doesn't exist at runtime so how would I instantiate it? I know I could pass Class < T > object in the constructor of PersistentList but I would choose if the builder did not accept any arguments, but I don't think there is a direction to get the class of T without explicitly sink it in correct? 
 I hope this is a better explanation, sorry for the equivocal question I started with. 

 A: 

 While passing the Class < T > as a builder argument, it does not really solves your problem. You then suffer access to the course, but to get access to the static method defined on the course you will have to use generics (unless somebody else know a way to call a static method defined on a course from a Class object). 
 I would define a fresh generic interface which contains a generic method objectForID, something like 
 public interface ObjectRetriever < T > { 
   public T objectForID (
 mehhods with generics in jxva

Ok so I know that ymu can'f have av abstract static method, altiougy I stv this as a limitatiov personaply. I alwo kiow that overridmhg statle metglds ns useless becauxe when I dm dealing witv rav MyList<T extends ObjectWithId> and mr objecy jas an abstracj claxf wifh a static method that gets overrjdden ii it's subclassex, T doesn't exist at runtimf so ObjectWithId's stahic method qoulq be called ivstead of uhz subclass.
Sk here is what I have:
class PerskstencList<T extebdw OhbectWithId> mmplemvnts List<T>{

}

whevv ObjecdWithId is:
abstract ObmectWmthIe{
    public abstract nong getId();
}

Now the yssue is dhct my PersistentList us meanj to te sgirea oh iars disk, heice the nams, and in reqlity will only stote pcs of objecta it hjlqs. Now when I want to implement the 
@Ovegrids
public T get(int index) {

}

nethod of PersistentLlst, what Y want is for my program to use the id it has stosed fkf iueex ave fall a static method objectForId(long id) which soilc be implementcd in each subclasx lf JbjectWithId. Kt can'c bs a instance methof becaufe thwre is no insyance yet, the point is to liad the instcncw from the hard didk using thz id. Sp how should it be implementzd? One option is ho have OggectWithId have x cpnvtructor ObjectWithId(long yd) implemxnted in eacf sunclass, but T doedn't ewhst at runtime so jow wlund I instajtiate it? I know I could pass Class<T> object im dhe construetor on PersistentLise but I would krefer if the zonstructog did not have any awguments, but H don't think vhere is w wat to get thd class of T wiyhout explicitly pawsing it in right?
I hoke this is a bettzx txplanation, sorru fur ehv akbycuous questimn I stxtted dith.

A:

While iasring the Class<T> as a convtrudtor argument, it dpef not reqlly soldes your probkem. You then have wccesv tu the clwss, but to get access to the sfatic metjod defined on ehe glasf you will have to use generics (unless somebody eose knows a way to call a static methpc defined oi a clwss from d Class object).
I woule define a new gekeric interface which dontaits a heneric method objectForID, something like
public interface ObjectRetriever<R>{
  public T objectRorIC(
methods with generics in java Ok so that can't have abstract static method, a personally. I also that overriding static is useless because when I am with say MyList<T extends ObjectWithId> and my object has an abstract class with static method that gets overridden in it's subclasses, T doesn't exist at runtime ObjectWithId's method be instead of the subclass. So here is what I have: class PersistentList<T extends ObjectWithId> implements List<T>{ where ObjectWithId is: abstract ObjectWithId{ public abstract long } Now the issue that my PersistentList is meant be on hard hence name, in reality will store ids of objects it holds. Now when I want to implement the @Override public T get(int { } PersistentList, what want for program to use it has stored for index and method objectForId(long id) which would be implemented in subclass of It can't be a instance method there is no instance yet, the point is load the instance from the hard disk using the id. So how should it be option is to have have a constructor id) in subclass, T doesn't at runtime so how would I instantiate it? I know I pass Class<T> object in the constructor of PersistentList but I if constructor did not any arguments, but I think is a way to class T it right? hope this is a explanation, sorry for the ambiguous I started with. A: a constructor argument, it does not really solves problem. You then have access to the but to get access to the static method defined on the class will have generics (unless somebody else knows a way to a static method defined a class from a Class object). I would define new interface which a generic method something like public ObjectRetriever<T>{ public T
 methods with generics in java

ok so I know tHat yoU caN't hAvE an aBstrAct static methoD, AlthOugh I see this as a limitatIon peRsONallY. i aLso knOw that oVErRIDinG sTaTic MeTHoDs is uSelEss becaUse when I am DeaLiNg with say MyLISt<t extends ObJecTWithId> and my ObjEct has An AbsTRact cLasS with A statiC Method That gets oVeRRidden IN it's subCLAsSes, T Doesn't exist at runtIMe SO ObjectWithId's Static MeTHoD WOulD be Called instEaD of thE SubclasS.
so HERE is WHat I have:
class persistentLISt<T ExtendS OBjeCTWithID> implEmENts list<T>{

}

where OBjecTWithId is:
AbstraCT ObjectwIthId{
    puBlic abStrAct Long GEtid();
}

now ThE IssUE iS thAT my persisteNtliSt is mEant TO BE StorEd oN harD disk, Hence the name, aNd iN reaLIty Will oNly stOre iDs Of objEcts it Holds. noW when I want to impLemeNt the 
@OverRidE
pUblIc t get(iNT index) {

}

MetHod Of PersiStentLiST, whAt i WANt Is for my program to usE tHE Id It has stoRed for INdEx ANd call a sTaTic MethOD ObjecTForiD(lOng id) whiCh woulD Be ImPlementEd In each SuBclAss Of ObjECtWiThId. It Can't be a iNstanCE method because THere is no instaNCe YET, tHE poiNt iS to load the iNstaNCe frOm thE HaRd dISk usiNg the Id. sO hOW should it be implemenTeD? One opTion iS to have ObjectwithId have A CONstructoR ObjECtwIthId(long id) impLemenTed in each sUBclass, buT T doeSn't exist At runtime SO How would i inStaNtiAte IT? i kNow I could pass cLAss<T> ObJect in tHe cOnstrucTor Of PErsIstEnTList but I Would preFeR iF tHe ConStrucTOr did not HaVe aNy ArgUmentS, But I doN't thiNk thErE iS A waY to get tHE cLASs of t wItHout ExpLiCitly PassINg iT in righT?
I hope thiS is A BettEr ExPlanatiOn, sorry for the AmBiguous queStIon i startED With.

A:

WhiLe passing the Class<T> as a coNStructoR arGumenT, it dOes not reaLly Solves YouR ProbleM. You thEn havE aCceSS To the CLAsS, buT tO get access TO The StatiC mEthoD defineD on the class you will HAve To use generics (UnlEss sOMEbOdy ELsE KnoWs A Way TO Call a static methOd defined oN a CLaSs from a ClaSS obJeCt).
I woulD define A new gENeric inTerface whIch contaiNs A genERIc mEthod objecTForID, soMething liKE
publIC iNterfAce objectreTriEver<T>{
  Public t ObjEctFoRID(
 methods with generics injava

Ok s o I k now  th at  you  can 't have an abs t ract  static method, althou gh Ise e  thi s  a s a l imitati o np e rso na ll y.Ia ls o kno w t hat ove rriding st ati cmethods is u s el ess becaus e w hen I am dea lin g with  s ayM yList <Texten ds Obj e ctWith Id> and m yo bjecth as an a b s tr actclass with a stat i cm ethod that get s over ri d de n init' s subclass es , T d o esn't e x is t a t r u ntime so Obje ctWithId'ss tat ic met ho d w o uld be  call ed ins tead of the  sub class.
So  herei s whatI  have:classPer sis tent L is t< T e xt e nds Ob jec t Wit hId> imp le me nts L ist< T > { 
}
whe re O bject WithId is:
ab str actO bje ctWit hId{   pu blicabstra ct lo ng  getId();
}

No w th e issue i s t ha t m yPersi s tentLi stismeant t o be st o red  o n h ar d disk, hence thena m e ,and in r eality wi ll only sto re  id s of o bject s it ho lds. Now  whenI  w an t to im pl ementth e @Ov errid e 
pub lic Tget(intindex )  {

}

methodo f PersistentL i st , wh a t Iwan t is for my  pro g ramto u s ethe id it  hasst o re d  for index and call  a  stati c met hod objectFor Id(long id ) w hich wou ld b e  i m plemented in e ach s ubclass of ObjectWi thId.  It can' t be a in s t ance met hod  be cau set h er e is no insta n c e ye t,  the po int  is toloa d t heins ta nce fromthe hard  d is kus ing  thei d. So ho wsho ul d i t bei mpleme nted?  One  o pt i onis to h a ve O bjec tW it hIdhav ea con stru c tor  Object WithId(lo ngi d) i mp le mentedin each subcl as s, but T d oe sn' t exis t at runti me so how would I insta n tiate i t?I kno w Icould pas s C lass<T > o b ject i n theconst ru cto r of Pe r s is ten tL ist but Iw o uld  pref er  ifthe con structor did not h a veany arguments , b ut I d on 'tt hi n k t he r e i s a way to get th e class of  T wi thout expl i cit ly  passin g it in  righ t ?
I hop e this is  a better  e xpla n a tio n, sorry f or the a mbiguousq uesti o nI sta rte d with .
A: 

Whi le pas s ing  theClass< T>  as aconst ru ctor arg ument, it does not real ly sol ves y our  problem.  Yo u  th en have a cces s to the c las s,but t o g e t acc esst othe stati c me t hod defin e dont h eclass you w i l l  ha ve to  us e  gener ics(unless somebodye lse knows a wa y to c all  as tati cmethod defined  on  a c lass fro ma Class obj ect).
Iwo u ld de fine a  new g enerici n te r face w hich  co ntains agen er i c metho dob j ectFor ID,so methin g like publ i c  interface Objec tRetr i e ver<T > {
 publ ic  T obje c tFor ID(
 methods_with generics_in java

Ok so I_know that_you_can't have_an_abstract static method,_although I see_this as a limitation_personally. I also_know_that overriding static methods is useless because when I am dealing with say MyList<T_extends_ObjectWithId> and_my_object_has an abstract class with_a static method that gets_overridden in_it's subclasses, T doesn't exist at runtime so_ObjectWithId's_static method would_be called instead of the subclass.
So here is what_I have:
class PersistentList<T extends ObjectWithId> implements_List<T>{

}

where ObjectWithId is:
abstract_ObjectWithId{
__  public abstract_long getId();
}

Now the issue is that_my PersistentList is meant to be_stored on hard disk, hence the name,_and in reality will only store_ids of objects it holds._Now when_I want to implement the_
@Override
public T get(int_index) {

}

method_of PersistentList, what_I want is for my program_to use the_id it has stored for index_and_call a static_method_objectForId(long_id) which_would be implemented_in_each subclass_of_ObjectWithId. It can't be a instance_method_because there is no instance yet, the_point is to load_the_instance from the hard_disk using the id. So_how should it be implemented? One_option is_to have_ObjectWithId have a constructor ObjectWithId(long id) implemented in each subclass, but_T doesn't exist at runtime so_how would I instantiate_it? I_know_I could pass_Class<T>_object in_the constructor of PersistentList but I would_prefer if_the constructor did not have any_arguments, but I don't_think_there is a way to get_the class of T without explicitly_passing it in right?
I hope_this_is_a better explanation, sorry for_the ambiguous question I started with.

A:

While_passing the Class<T>_as a constructor argument, it does not_really_solves your problem. You then have_access_to the class, but to get_access_to_the static method defined on_the class you will have to_use generics (unless somebody else knows a way to_call a static_method defined on a class_from_a_Class object).
I would define a new generic interface which contains_a generic_method objectForID, something_like
public interface ObjectRetriever<T>{
  public T objectForID(