Java – generic parameters for serializable collections

I have such members in a serializable class:

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

This class has the following type boundaries

<T extends Serializable>

I use findbugs to check for errors in my code, which shows me that the member is "not (guaranteed to be serializable)"

Solution

Because your serializable class contains the following members

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

Here, t can be any class foo, which is not guaranteed to be serializable, so it is a warning / suggestion / eye opener

If you want it to be serializable in all cases instead of making it

List<? extends Serializable>

If you don't want to serialize that field at all, just mark it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>