I have read the dozens of questions here on SO regarding recycling TypedArray
s, but I guess they are a bit too old and written before we could widely use try-with-resource
statements, so none of them talk about using the AutoCloseable
implementation of the TypedArray
, which is present since API Level 31
So the question remains: is this a false positive in Lint?
If anything, that warning should be a minSDK warning if applicable, right? Can we simply write the following since the full try-with support (if we do it after SDK Level >= 31 check)?
try (TypedArray array = getContext().obtainStyledAttributes(attrs) {
// Do someting
}
// End of method
My guess is yes, as this is the AutoCloseable
implementation of TypedArray