https://kotlinlang.org logo
t

tylerwilson

10/14/2016, 8:20 PM
Okay, more advanced question. I had Java code like this:
Copy code
class Sounds {
        private static class Style {
           static final String Version1 = "path/to/resource";
       }
}`
Kotlin converted it to:
Copy code
object Sounds {
          private class Style {
             companion object {
               internal val Version1 = "path/to/resource"
             }
         }
    }
The tricky thing on the Java side was to look up the values dynamically, using the field names like so:
Copy code
result = (String)Style.class.getDeclaredField(key).get(null);
which was converted to Kotlin:
Copy code
Style::class.java.getDeclaredField(key).get(null) as String
but the Kotlin version always returns null. Is there some special magic sauce to make getDeclaredField working? Does that make sense?