Why init instead of static

Jump to navigation Jump to search

Why init instead of static

Chase, I believe the reason to use the init method instead of a static block within this class is that the static block won't be called until this class is loaded by the JVM the first time it's used. By using an init method and calling it from a static block in your bot class, you ensure it's called when your bot is loaded, before the battle starts and not causing any skipped turns. Hopefully somebody can confirm/deny that.

Voidious14:25, 18 September 2011

Voidious, you right in common, but there're an issue - robots are loaded in theirs threads, so you can skip turns any way.

Jdev14:33, 18 September 2011
 

IIRC, while there is a limit on the time for a robot's class to load, it is far greater than the time allowed per turn.

Rednaxela15:05, 18 September 2011
 

You do not have permission to edit this page, for the following reasons:

  • The action you have requested is limited to users in the group: Users.
  • You must confirm your email address before editing pages. Please set and validate your email address through your user preferences.

You can view and copy the source of this page.

Return to Thread:User talk:Rednaxela/FastTrig/Why init instead of static/reply (3).

 

It's been a long time, but when first writing FastTrig, I believe I tested this, and found that classes like this were initialized upon first reference.

Rednaxela00:36, 19 September 2011
 

I'll test it later.

Chase-san00:40, 19 September 2011
 

I debugged initialization order. Looks like everything is initialized before the battle starts thanks to some field cleaning algorithm inside the engine (net.sf.robocode.host.security.RobotClassLoader#cleanStaticReference(java.lang.reflect.Field)).

MN22:11, 19 February 2012
 

Yeah I added my little init hack awhile back so people could have it either way. So if you forgot to init it wouldn't break on you, and you could init if you really wanted to/it made you feel better.

Chase-san20:08, 20 February 2012