- Yes, the whole point of pre-compiling a
Patternis to only do it once. - It really depends on how you’re going to use it, but in general, pre-compiled patterns stored in
staticfields should be fine. (UnlikeMatchers, which aren’t threadsafe and therefore shouldn’t really be stored in fields at all, static or not.)
The only caveat with compiling patterns in static initializers is that if the pattern doesn’t compile and the static initializer throws an exception, the source of the error can be quite annoying to track down. It’s a minor maintainability problem but it might be worth mentioning.