我有一个Thrift IDL如下:
union Container {
1: Point point;
2: Polygon polygon;
}
如果我有Container
个对象,如何检查Container
是Point
还是Polygon
?看起来它应该是一个微不足道的检查,但我无法弄清楚如何......
Container container = <some-container>
Point point = container.getPoint(); // will error if the container is a polygon
Polygon polygon = container.getPolygon(); // will error if the container is a point