title: Kotlin, how to retrieve field value via reflection
body: <p>So I have hundreds of fields in a couple of <a href="https://github.com/kotlin-graphics/uno-sdk/blob/master/src/main/kotlin/uno/caps/caps.kt" rel="noreferrer">classes</a> and I'd like to write some methods on them where they automatically <code>println</code> each field and its corresponding value</p>
  
  <p>At the moment I have this:</p>
  
  <pre><code>inner class Version(val profile: Profile) {
  
      @JvmField val MINOR_VERSION = glGetInteger(GL_MINOR_VERSION)
  
      fun write(file: File? = null) {
          //file.printWriter().use { out -&gt; out.pri }
          this::class.java.fields.forEach {
              println(it.isAccessible)
              println(it.getInt(it)) }
      }
  }
  </code></pre>
  
  <p>But this is what I get:</p>
  
  <pre><code>false
  Exception in thread "main" java.lang.IllegalArgumentException: Can not set final int field uno.caps.Caps$Version.MINOR_VERSION to java.lang.reflect.Field
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
      at sun.reflect.UnsafeQualifiedIntegerFieldAccessorImpl.getInt(UnsafeQualifiedIntegerFieldAccessorImpl.java:58)
  </code></pre>
  
  <p>Any idea?</p>