java - static / abstract conflict -


i have abstract class (averageddatarecord) need abstract further (datarecord) can extend original class , new concrete class (summeddatarecord) , i'm having problems getting of methods translate original abstract class new super class.

public abstract class datarecord{   protected abstract datarecord getfirstrecord(arraylist<t> datalist);   protected abstract datarecord getlastrecord(arraylist<t> datalist);    protected datetime getfirstrecordtimestamp(arraylist<t> datalist){     datetime result   = new datetime(default_datetime);     datarecord record = this.getfirstrecord(datalist);     if(null != record)       result = record.getrecorddatetime();     return result;   }    protected datetime getlastrecordtimestamp(arraylist<t> datalist){     datetime result   = new datetime(default_datetime);     datarecord record = this.getlastrecord(datalist);     if(null != record)       result = record.getrecorddatetime();     return result;   } }  public abstract class averageddatarecord extends datarecord<averageddatarecord> {   public averageddatarecord getfirstrecord(arraylist<averageddatarecord> datalist){     // implementation   }    public averageddatarecord getlastrecord(arraylist<averageddatarecord> datalist){     // implementation   }    public static void mymethod(arraylist<averageddatarecord> datalist){     // beginning of method code     filewriter.write(itema, itemb, **getlatesttimestamp(datalist)**);     // end of method code   } } 

the issue having noted method call above shows error. "quick fix" suggesting getlatesttimestamp() needs static.

making getlatesttimestamp() static gives me error on declaration because java "cannot make static reference non-static type t".

i've chased , down quick fixes , haven't found mention of particular problem in forums belong nor on google. can't believe i'm person ever happened if solution out there, haven't been fortunate enough find it.

if going use getlatesttimestamp() in static context, i.e. in static method, getlatesttimestamp() must static method, why quick-fix suggests marking getlatesttimestamp method static. on other hand can create instance of class in getlatesttimestamp method defined , access getlatesttimestamp via reference.

to use non-static method in static context, must access non-static method via reference.

remember, non-static fields cannot used in static context, except via reference.


replace getlatesttimestamp(datalist) in code following:

    new /*/().getlatesttimestamp(datalist);      // replace /*/ name of class in getlatesttimestamp created 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -