It’s obvious that you don’t put any kind of heavy computation into a static initialiser. Anything that uses parallel stream would be by definition heavy.
You can't judge how heavy a computation is by looking at the code in your static initializer. You might just do "new Foo()" and THAT inside uses parallel streams for some reason.
If they wanted to restrict calling arbitrary code... they should've restricted calling arbitrary code.
Well, when you program, you don't just slap constructor and method invocations here and there. More often than not you get a rough idea what are the runtime characteristics of the used APIs: memory usage and algorithm complexity. Say, Java doesn't have a single best-for-all Set implementation, you need to pick the one that suits your case.
35
u/AndrewHaley13 Mar 21 '21
Well, this kind of edge case really needs to be fixed. It's far from obvious that lambda streams shouldn't be used in static initializers.