Does Pattern.compile cache?

前端 未结 5 642
盖世英雄少女心
盖世英雄少女心 2020-12-04 01:54

It is likely an implementation detail, but for the Oracle and IBM JDKs at least is the compiled pattern cached or do we as application developers need to perform the caching

5条回答
  •  清歌不尽
    2020-12-04 02:21

    It doesn't. If you have performance sensitive areas, you might want to hold your pattern objects as member variables.

    Clojure does this more or less automatically when you have a regex in a function though.

提交回复
热议问题