문제

Initialization of scala.Predef class is lazy heavyweight operation which may cause unexpected slowdown of application and will become a trouble in situations when timing matters (like programming contests).

val a = new Array[Integer](10)
a(5) = 3 //slowdown on this line

So can I turn off it's laziness and force scala.Predef initialization on application start using only scala compiler or VM options without making changes in the code?

도움이 되었습니까?

해결책

No you can't. You can initialize an object by calling it, like this

Predef    // ensures the body of Predef is initialized
val a = new Array[Integer](10)
a(5) = 3

Still, you will probably not have initialized the ArrayOps class which is involved in a.apply. Lazy class initialization is a property of the JVM. If you do benchmarks, that's why you usually give it a "warmup" run first, so that all involved classes have been loaded first.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top