Java – How to solve the lint warning “field is never used” but it is serialized

How to solve the lint warning “field is never used” but it is serialized… here is a solution to the problem.

How to solve the lint warning “field is never used” but it is serialized

I

have a small class in my Android project that contains some variables and I allocate them in the constructor.

Then I use the Gson library and functions to serialize the object into json String Gson::toJson(Object src).

How do I fix this lint warning: “Private field is assigned but never accessed” on these variables? Are there special comments on that case?

EDIT: Sorry, there is another warning “fields can be converted to local variables”, which is wrong!

Thanks!

Solution

You can add @SuppressWarnings("unused") comments on fields to prevent such messages from being generated.

Related Problems and Solutions