iterator - Converting types in Java -


java noob here,

i have iterator<typea> want convert iterator<typeb>. typea , typeb cannot directly cast each other can write rule how cast them. how can accomplish this? should extend , override iterator<typea>'s next, hasnext , remove methods?

thanks.

you don't need write yourself. guava (formerly google-collections) has covered in iterators.transform(...)

you provide iterator , function converts typea typeb , you're done.

iterator<typea> itera = ....; iterator<typeb> iterb = iterators.transform(itera, new function<typea, typeb>() {    @override    public typeb apply(typea input) {      typeb output = ...;// rules create typeb typea      return output;    } }); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -