title: IllegalArgumentException when setting public member
body: <p>I've been playing around with reflection in Java... and I'm a little bit baffled.</p>
  
  <p>I was hoping that the program below would allow me to change the value of a public member variable within a class. However, I receive an IllegalArgumentException. Any ideas?</p>
  
  <pre><code>public class ColinTest {
  
      public String msg = "fail";
  
      public ColinTest() { }
  
      public static void main(String args[]) throws Exception {
          ColinTest test = new ColinTest();
          Class c = test.getClass();
          Field[] decfields = c.getDeclaredFields();
          decfields[0].set("msg", "success");
  
          System.out.println(ColinTest.msg)
      }
  }
  </code></pre>
  
  <p>I receive this message - </p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalArgumentException
      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
      at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:57)
      at java.lang.reflect.Field.set(Field.java:656)
      at ColinTest.main(ColinTest.java:44)
  </code></pre>
  
  <p>Thanks.</p>