NotSerializableException: java.util.regex.Matcher

三世轮回 提交于 2019-12-24 20:36:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!