Private fields don't have generics information in compiled classes; is it intended?


#1

Hi,

look at the following Java Class:
``

import java.util.List;

class GenericsTest {
  private final List<String> test = null;
}

Compiling this class using Java 6 (I used javac 1.6.0_45) or Java 7 (I used javac 1.7.0_13) and using javap -private GenericsTest, I get the following output:

``

class GenericsTest {
  private final java.util.List<java.lang.String> test;
  GenericsTest();
}

As you can see, we have generics information available for the private field. Now, look at the following Kotlin class:

``

public class GenericsTest {
     private var test: List<String>? = null;
}

Compiling this class using the latest Kotlin nightly (I used 0.5.684) and using javap as above, I get the following output:

``

public final class GenericsTest implements jet.JetObject {
  private java.util.List test;
  private final java.util.List<java.lang.String> getTest();
  private final void setTest(java.util.List<? extends java.lang.String>);
  public GenericsTest();
}

As you can see, we have no generics information for the private field. The same holds for public/protected fields (they are compiled to private fields, only setter/getter change). Yes, we do have this information somehow in the setter/getter but that is not optimal in my opinion.

So my question: Is this intended or just a bug?

Regards
Julian


#2

Looks like a bug. Please report to the tracker.


#3

Long question, short answer, thanks :) I created a ticket: http://youtrack.jetbrains.com/issue/KT-3641 http://youtrack.jetbrains.com/issue/KT-3641Looking forward to seeing the next Kotlin milestone :)