David Rogers
03/04/2022, 10:04 PMimport Foo.Bar; // does this trigger a classload of Foo.Bar, or just fixup mappings
component {
function init() {
var x = Bar::staticProp; // guaranteed to be init'd?
}
}
Daniel Mejia
03/04/2022, 10:05 PMDavid Rogers
03/04/2022, 10:06 PMDaniel Mejia
03/04/2022, 10:07 PMDavid Rogers
03/04/2022, 10:07 PMDaniel Mejia
03/04/2022, 10:08 PMDaniel Mejia
03/04/2022, 10:08 PMDavid Rogers
03/04/2022, 10:08 PMDaniel Mejia
03/04/2022, 10:09 PMDavid Rogers
03/04/2022, 10:09 PMstaticProp
?David Rogers
03/04/2022, 10:13 PMAdam Cameron
Adam Cameron
David Rogers
03/04/2022, 10:22 PMDavid Rogers
03/04/2022, 10:22 PMAdam Cameron
writeOutput("did this run?")
in the static constructor. When would that appear? On the import? On the access of the static variable?David Rogers
03/04/2022, 10:26 PMAdam Cameron
// guaranteed to be init'd?
... no it's absolutely not guaranteed to be inited. Static variables belong to the class, not an object instance of the class. One does not need an object instance of Foo to access Foo::barAdam Cameron
Adam Cameron
Adam Cameron
Foo::
)Adam Cameron
David Rogers
03/04/2022, 10:31 PMBar::
would trigger a classload of Bar.cfc, i don't see anything that promises that, so I'm being paranoid.Adam Cameron
Adam Cameron
Adam Cameron
Foo::BAR
that I get an expected value.Adam Cameron
David Rogers
03/04/2022, 10:41 PMDaniel Mejia
03/04/2022, 10:44 PMDavid Rogers
03/04/2022, 10:45 PMSomeComponent::someStaticProp
Daniel Mejia
03/04/2022, 10:45 PMAdam Cameron
Adam Cameron
Daniel Mejia
03/04/2022, 10:47 PM// Example3.cfc
Component {
//instance constructor body
dump("this is executed every time a new instance is created");
//static constructor body
static {
dump("this is executed only if the component is loaded for the first time");
}
}
David Rogers
03/04/2022, 10:48 PMAdam Cameron
SomeComponent
, but never access any of its static stuff, does its "class" still load?Adam Cameron
David Rogers
03/04/2022, 10:51 PMAdam Cameron
Adam Cameron
Daniel Mejia
03/04/2022, 10:56 PMDavid Rogers
03/04/2022, 10:58 PMDaniel Mejia
03/04/2022, 11:00 PMAdam Cameron
David Rogers
03/04/2022, 11:07 PMstatic {}
initializer block syntax from javaDavid Rogers
03/04/2022, 11:09 PMstatic { }
instead of staticInit() {}
)Daniel Mejia
03/04/2022, 11:30 PMDaniel Mejia
03/04/2022, 11:32 PMDaniel Mejia
03/04/2022, 11:33 PMDavid Rogers
03/04/2022, 11:55 PMFoo::
?
import Foo;
sys = createObject("java", "java.lang.System");
function benchSlow() {
var result = [];
for (i = 0; i < 100; i++) {
var start = sys.nanotime();
var v = Foo::someProp;
var end = sys.nanotime();
result.append(end - start)
}
writedump((result.avg() / 1e6) & "ms"); // 0.0130ms
}
function bench2() {
var result = [];
var someProp = Foo::someProp;
for (i = 0; i < 100; i++) {
var start = sys.nanotime();
var v = someProp;
var end = sys.nanotime();
result.append(end - start)
}
writedump((result.avg() / 1e6) & "ms"); // .0007ms
}
Daniel Mejia
03/05/2022, 12:24 AMstatic {
static.CACHE_KEY = "BRICKONE"
}
Daniel Mejia
03/05/2022, 12:27 AMstatic
scope inside the static block better or required?Adam Cameron
Andreas
03/06/2022, 9:52 AMAndreas
03/06/2022, 9:52 AMDaniel Mejia
03/08/2022, 2:36 AM