Java API to find out the JDK version a class file is compiled for?

前端 未结 8 986
星月不相逢
星月不相逢 2020-11-28 07:52

Are there any Java APIs to find out the JDK version a class file is compiled for? Of course there is the javap tool to find out the major version as mentioned in here. Howev

8条回答
  •  一生所求
    2020-11-28 08:01

    This gets you the contents of the class file:

    MysteryClass.class.getResourceAsStream("MysteryClass.class")

    Then look at bytes 5-8 to get the minor and major version. A mapping between those numbers and the JDK releases can be found here.

提交回复
热议问题