Accessing fields of Thrift-generated Java classes directly instead of through provided getters

StackOverflow https://stackoverflow.com/questions/20480740

  •  30-08-2022
  •  | 
  •  

I'm somewhat new to Thrift. I have a bunch of Thrift-generated Java classes whose instances I need to read values from. I did not generate the classes, nor did I design the Thrift definitions.

I notice that there are public getters and setters for every field in the generated class (each field corresponding to a field in the Thrift definitions). But also (and, oddly) that the fields are themselves public.

What I'd like to know is, would it be "OK" (in terms of Thrift practice in Java) to read the fields directly instead of using the getters?

Thanks much!

有帮助吗?

解决方案

REgarding getters, it is probably perfectly OK to read from them directly.

The typical implementation across all languages is, that only the setters for optional fields serve the additional purpose of setting the isset flag for the field being set.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top