I just found a bug in some code I didn\'t write and I\'m a bit surprised:
Pattern pattern = Pattern.compile(\"\\\\d{1,2}.\\\\d{1,2}.\\\\d{4}\");
Matcher matc
Pattern
is to only do it once.static
fields should be fine. (Unlike Matcher
s, 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.