Java - 获取派生类

时间:2016-11-06 11:24:24

标签: java

所以我有一个名为" User"的抽象类。和两个派生的类名为"卖方"和"买方"。我还有一个用户向量,我推送卖家和买家......我的问题是:如果我从向量中获得一个随机元素,我怎么知道它是卖家还是卖家的元素? 感谢

1 个答案:

答案 0 :(得分:0)

在随机对象上使用def bfs_paths(graph, start, goal): queue = [(start, [start])] while queue: (vertex, path) = queue.pop(0) for next in graph[vertex] - set(path): if next == goal: yield path + [next] else: queue.append((next, path + [next])) def shortest_path(graph, start, goal): try: return next(bfs_paths(graph, start, goal)) except StopIteration: return None 并使用if()条件来检查它是否为'买方或卖方