Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic arguments for serializable collections

i have a member like this in a serializable class:

private final Map<String, List<T>> categoryMap = Maps.newHashMap();

the class has the following type-bounds.

<T extends Serializable>

I use findbugs to check for mistakes in my code, and it shows me that member as "not (guaranteed to be) serializable".

like image 944
Fabian Zeindl Avatar asked Dec 01 '25 10:12

Fabian Zeindl


1 Answers

Because your serializable class contains the following member

private final Map<String, List<T>> categoryMap

here T can be any class Foo, which isn't guaranteed to be Serializable and so the warning/suggestion/eye opener

If you are expecting it to be serializable in all the cases than make it

List<? extends Serializable>

and if you don't want to seralize that field at all simply mark transient

like image 160
jmj Avatar answered Dec 02 '25 22:12

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!