Hi guys. I just wrote this simple object ``` objec...
# announcements
k
Hi guys. I just wrote this simple object
Copy code
object Test {
    private val map = hashMapOf(
        "abc" to "something", 
        "def" to "another",
        "ghi" to "yet another")

    val abc by map
    val def by map
    val ghi by map
}
But the generated bytecode has several references and reflection. I’m curious why that is the case. Is there any way that the generated code can be made much more optimized? Or perhaps I might be missing something 🤔 Here’s the raw Java translation
Copy code
public final class Test {
   // $FF: synthetic field
   static final KProperty[] $$delegatedProperties = new KProperty[]{(KProperty)Reflection.property1(new PropertyReference1Impl(Reflection.getOrCreateKotlinClass(Test.class), "abc", "getAbc()Ljava/lang/String;")), (KProperty)Reflection.property1(new PropertyReference1Impl(Reflection.getOrCreateKotlinClass(Test.class), "def", "getDef()Ljava/lang/String;")), (KProperty)Reflection.property1(new PropertyReference1Impl(Reflection.getOrCreateKotlinClass(Test.class), "ghi", "getGhi()Ljava/lang/String;"))};
   private static final HashMap map;
   @NotNull
   private static final HashMap abc$delegate;
   @NotNull
   private static final HashMap def$delegate;
   @NotNull
   private static final HashMap ghi$delegate;
   public static final Test INSTANCE;

   static {
      Test var0 = new Test();
      INSTANCE = var0;
      map = MapsKt.hashMapOf(new Pair[]{<http://TuplesKt.to|TuplesKt.to>("abc", "something"), <http://TuplesKt.to|TuplesKt.to>("def", "another"), <http://TuplesKt.to|TuplesKt.to>("ghi", "yet another")});
      abc$delegate = map;
      def$delegate = map;
      ghi$delegate = map;
   }

   @NotNull
   public final String getAbc() {
      Map var1 = (Map)abc$delegate;
      KProperty var3 = $$delegatedProperties[0];
      return (String)MapsKt.getOrImplicitDefaultNullable(var1, var3.getName());
   }

   @NotNull
   public final String getDef() {
      Map var1 = (Map)def$delegate;
      KProperty var3 = $$delegatedProperties[1];
      return (String)MapsKt.getOrImplicitDefaultNullable(var1, var3.getName());
   }

   @NotNull
   public final String getGhi() {
      Map var1 = (Map)ghi$delegate;
      KProperty var3 = $$delegatedProperties[2];
      return (String)MapsKt.getOrImplicitDefaultNullable(var1, var3.getName());
   }
}