问题
Given that java.util.regex.Matcher
does not implement Serializable
, is it somehow possible to serialize a class that privately declares and uses
private Pattern pattern;
private Matcher matcher;
What, if any, workaround is possible here?
回答1:
make the Matcher transient so that it wont be serialized, as transient variables are not serialized..
private transient Matcher matcher;
来源:https://stackoverflow.com/questions/14901766/notserializableexception-java-util-regex-matcher