title: Prevent or Protect Against Reflection
body: <p>I am trying frantically to run a <a href="https://codegolf.stackexchange.com/q/25347/18487">programming competition</a> over on the Code Golf Stack Exchange. I wrote a small control program that pits animals against each other on a game board. The animals are mostly Java classes (CrazyWolf.java, SuicideWolf.java, etc.), written by other people.</p>
  
  <p>Those guys find so many loopholes in a competition that it will make your head spin. Some of them are starting to write Wolves that use reflection to cripple the competition before the simulation even begins.</p>
  
  <p>I look at this from two standpoints.</p>
  
  <ul>
  <li>Can I protect classes in the same package against reflection?</li>
  <li>Can the competitors themselves protect their own Wolf against reflection?</li>
  </ul>
  
  <p>With regard to the first question, the closest answer I could find on Stack Overflow was <a href="https://stackoverflow.com/a/770672/3224483">this one</a>, which addresses restricting access to <em>other</em> packages. All of the wolves inherit from the same <code>Animal</code> class, so the class has to be accessible.</p>
  
  <p>With regard to the second question, I found nothing. It seems like reflection just tramples over everything I thought I knew about private and even final variables. I did manage to find an article about tricking the compiler into replacing static final variables with a constant that won't be affected by reflection, but it seems unreliable and requires fields to be static and final.</p>
  
  <p>What methods can I use to solve this? I am using Java 8 and NetBeans 7.4.</p>