Provide an iterator over the contents of two lists simultaneously?

前端 未结 11 2053
逝去的感伤
逝去的感伤 2020-12-03 04:45

Suppose I have this:

public class Unit {

    ...

    List mobileSuits;
    List pilots;

    ...
}
         


        
11条回答
  •  隐瞒了意图╮
    2020-12-03 05:21

    Why not have a class MannedMobileSuit as a subclass of MobileSuit that contains an instance of a pilot ? That would solve your problem by having a getPilot method.

    Usually when you get such problems (needing to return two instances) it is because your Object model is not appropriate and should be changed. Keep your options open

提交回复
热议问题