javac - Incompatible types in "For Statement" during java recomplile -



javac - Incompatible types in "For Statement" during java recomplile -

all,

1st off not java programmer - have learned know in past 2 days trying recomplile class file. have reviewed every post here has 'incompatible types' still can't resolve issue. have java file no class file , receive next error when seek recompile it.

error:

source\idm\sap\configdatatm.java:153: incompatible types found : java.lang.object required: idm.sap.configdatatm /* 177 */ (configdatatm x : xlist) {

source:

/* */ public boolean add(configdatatm element) /* */ { /* 161 */ homecoming this.rootdata.add(element); } /* 162 */ public boolean addsysfile(string filename) { homecoming add(new configdatatm (filename, "sys", true)); } /* 163 */ public boolean addpasswdfile(string filename) { homecoming add(new configdatatm(filename, "pass", true)); } /* 164 */ public boolean addvpnfile(string filename) { homecoming add(new configdatatm(filename, "vpn", true)); } /* */ /* */ public string getfiletobeloaded(string filetype) /* */ { /* 168 */ if ((!filetype.equals("sys")) && (!filetype.equals("pass")) && (!filetype.equals("vpn"))) { /* 169 */ system.err.println("[configdatatm] warning: bad type"); /* 170 */ homecoming null; /* */ } /* */ /* 173 */ string filename = null; /* 174 */ list xlist = getvector(); /* */ /* 176 */ if (xlist != null) { /* 177 */ (configdatatm x : xlist) { /* 178 */ if ((x != null) && /* 179 */ (x.getloadflag()) && (filetype.equals(x.gettype()))) filename = x.getfilename(); /* */ } /* */ /* */ } /* */ /* 184 */ homecoming filename; /* */ }

i know there error has configdatatm element , xlist variable, beyond lost.

any help appreciated.

this generics. compiler trying ensure type safety -- every object in xlist instance of configdatatm. since type of xlist not have generic parameter defaults object. is, can hold type of object, not instances of configdatatm. around must either create sure generic type of xlist handled (ensuring compile time safety) or explicitly utilize cast (giving runtime safety).

eg. (with generics)

list<configdatatm> xlist = getvector(); // requires getvector() homecoming list<configdatatm>

and without generics

for (object object : xlist) { configdatatm x = (configdatatm) object; ...

with non-generics if x not instance of configdatatm runtime exception thrown , application crash. if generics used compiler able check how list handled @ compile time , sure instances of configdatatm stored in xlist.

java javac foreach

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -