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