从文档中:Thrift默认将SET容器转换为HashSet。我们可以改变这种行为吗?
集装箱 Thrift容器是强类型容器,可以映射到大多数编程语言中常用和常用的容器类型。
https://thrift.apache.org/docs/types:
有三种容器类型: list:元素的有序列表。转换为STL向量,Java ArrayList,脚本语言中的本机数组等。 set:一组无序的独特元素。转换为STL集,Java HashSet,在Python中设置等。注意:PHP不支持集合,因此它被视为类似于List
答案 0 :(得分:0)
sorted_containers
选项切换为
TreeMap
map<>
{li> TreeSet
set<>
在调用Thrift编译器时要指定选项,如下所示:
$ thrift -gen java:sorted_containers myfile.thrift
以下是可用于Java的所有选项(curent master branch,thrift -help
显示更多信息)
java (Java):
beans: Members will be private, and setter methods will return void.
private-members: Members will be private, but setter methods will return 'this' like usual.
nocamel: Do not use CamelCase field accessors with beans.
fullcamel: Convert underscored_accessor_or_service_names to camelCase.
android: Generated structures are Parcelable.
android_legacy: Do not use java.io.IOException(throwable) (available for Android 2.3 and above).
option_type: Wrap optional fields in an Option type.
java5: Generate Java 1.5 compliant code (includes android_legacy flag).
reuse-objects: Data objects will not be allocated, but existing instances will be used (read and write).
sorted_containers:
Use TreeSet/TreeMap instead of HashSet/HashMap as a implementation of set/map.
generated_annotations=[undated|suppress]:
undated: suppress the date at @Generated annotations
suppress: suppress @Generated annotations entirely
其他选项不可用。 C ++生成器支持注释,这似乎与Java不同。我是否提到we accept patches?