Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am reading Herbert Schilds about type erasure in generics in java. Supposedly running javap on a class should give me the bytecode information about public, package protected and protected fields and methods after type erasure. However, I wrote the following class:

    class Ambiguity<T, V extends String>{
    T ob1;
    V ob2;

    void set(T o){
        ob1 = o;
    }

    void set(V o){
        ob2 = o;
    }
}

and ran javap on the class file that was generated and got the following output

Compiled from "Test.java"

class Ambiguity<T, V extends java.lang.String> {
  T ob1;
  V ob2;
  Ambiguity();
  void set(T);
  void set(V);
}

I was expecting an output that looked like this based on what I read.

Compiled from "Test.java"
class Ambiguity<java.lang.Object, java.lang.String> {
  java.lang.Object ob1;
  java.lang.String ob2;
  Ambiguity();
  void set(java.lang.Object);
  void set(java.lang.String);
}

Am I missing something here? I should add that I understand that it is not a good practice to overload methods in the above manner. I was just seeing interested in seeing the results of javap under this ambiguity.

EDIT: This seems to be a result of a new fix in javap. http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4870651

If I run javap from JDK 1.6 I get the results as I was expecting. If I run javap from JDK 1.7 b30 which was what I was using initially, I get the result with the generic information.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
402 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm not sure. But it seems signature attribute was introduced in jvm 7 (refer jvm specification).

This attribute will capture signature information used for debugging and reflection api.

To see signature attribute use javap -v <class>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...