javap throws exception when invoked on a valid class accepted by VM.
The following class overloads method name based on return type only.
This class was created using jasmin (http://www.cat.nyu.edu/meyer/jasmin/) assembler.
----------------------------Overloading based on return type -----------------
.class or
.super java/lang/Object
; This class has two methods having same name , same argument types
; and different return types.
; Code is written in jasmin assembly language
; which is equivalent to the following psuedo java code.
; Note that though java does not allow return type based
; overloading of methods, jvm allows the same.
;******************** NOT JAVA ************************************
; class or
; {
; public static void main(String[] args)
; {
; System.out.println(main(args);
; }
;
; public static int main(String args[])
; {
; System.out.println("inside int main(String[])");
; return 2;
; }
;
;******************************************************************
.method static public main([Ljava/lang/String;)V
.limit locals 1
.limit stack 3
getstatic java/lang/System/out Ljava/io/PrintStream;
aload_0
invokestatic or/main([Ljava/lang/String;)I
invokevirtual java/io/PrintStream/println(I)V
return
.end method
.method static public main([Ljava/lang/String;)I
.limit stack 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc "inside int main(String[])"
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
iconst_2
ireturn
.end method
---------------------------------------------------------------------------
The above class is accepted by java VM. javap throws "duplicate" method
exception.
---------------------- javap result -----------------------------------
Exception in thread "main" sun.tools.java.CompilerError: duplicate addition
at sun.tools.java.MethodSet.add(MethodSet.java:88)
at sun.tools.java.ClassDefinition.collectInheritedMethods(ClassDefinitio
n.java:1475)
at sun.tools.java.BinaryClass.basicCheck(BinaryClass.java:76)
at sun.tools.java.ClassDeclaration.getClassDefinition(ClassDeclaration.j
ava:133)
at sun.tools.java.Environment.getClassDefinition(Environment.java:126)
at sun.tools.javap.JavaP.displayResults(JavaP.java:196)
at sun.tools.javap.JavaP.perform(JavaP.java:215)
at sun.tools.javap.JavaP.entry(JavaP.java:236)
at sun.tools.javap.JavaP.main(JavaP.java:223)
-----------------------------------------------------------------------------
But javap accepts field name overloading.
-------------------- overloading field names ------------------------------
.class of
.super java/lang/Object
; This class overloads field names. Code is written in jasmin
; assembly language. Though java does not allow field name overloading
; jvm allows the same.
; the code is equivalent to following pseudo java code
;
;
; ********************** NOT JAVA ***************************
;
; class of
; {
; static int x;
; static long x;
;
; public static void main(String[] args)
; {
; (int) x = 100; // assign 100 to int x
; (long) x = 1; // assign 1 to long x
; System.out.println((int)x);
; System.out.println((long)x);
;
; }
; }
;
;
;**********************************************************
.field static x I
.field static x J
.method static public main([Ljava/lang/String;)V
.limit stack 5
.limit locals 2
bipush 100
putstatic of/x I
lconst_1
putstatic of/x J
getstatic java/lang/System/out Ljava/io/PrintStream;
getstatic of/x I
invokevirtual java/io/PrintStream/println(I)V
getstatic java/lang/System/out Ljava/io/PrintStream;
getstatic of/x J
invokevirtual java/io/PrintStream/println(J)V
return
.end method
---------------------------------------------------------------------------
Both java and javap accept this class.
The following class overloads method name based on return type only.
This class was created using jasmin (http://www.cat.nyu.edu/meyer/jasmin/) assembler.
----------------------------Overloading based on return type -----------------
.class or
.super java/lang/Object
; This class has two methods having same name , same argument types
; and different return types.
; Code is written in jasmin assembly language
; which is equivalent to the following psuedo java code.
; Note that though java does not allow return type based
; overloading of methods, jvm allows the same.
;******************** NOT JAVA ************************************
; class or
; {
; public static void main(String[] args)
; {
; System.out.println(main(args);
; }
;
; public static int main(String args[])
; {
; System.out.println("inside int main(String[])");
; return 2;
; }
;
;******************************************************************
.method static public main([Ljava/lang/String;)V
.limit locals 1
.limit stack 3
getstatic java/lang/System/out Ljava/io/PrintStream;
aload_0
invokestatic or/main([Ljava/lang/String;)I
invokevirtual java/io/PrintStream/println(I)V
return
.end method
.method static public main([Ljava/lang/String;)I
.limit stack 2
getstatic java/lang/System/out Ljava/io/PrintStream;
ldc "inside int main(String[])"
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
iconst_2
ireturn
.end method
---------------------------------------------------------------------------
The above class is accepted by java VM. javap throws "duplicate" method
exception.
---------------------- javap result -----------------------------------
Exception in thread "main" sun.tools.java.CompilerError: duplicate addition
at sun.tools.java.MethodSet.add(MethodSet.java:88)
at sun.tools.java.ClassDefinition.collectInheritedMethods(ClassDefinitio
n.java:1475)
at sun.tools.java.BinaryClass.basicCheck(BinaryClass.java:76)
at sun.tools.java.ClassDeclaration.getClassDefinition(ClassDeclaration.j
ava:133)
at sun.tools.java.Environment.getClassDefinition(Environment.java:126)
at sun.tools.javap.JavaP.displayResults(JavaP.java:196)
at sun.tools.javap.JavaP.perform(JavaP.java:215)
at sun.tools.javap.JavaP.entry(JavaP.java:236)
at sun.tools.javap.JavaP.main(JavaP.java:223)
-----------------------------------------------------------------------------
But javap accepts field name overloading.
-------------------- overloading field names ------------------------------
.class of
.super java/lang/Object
; This class overloads field names. Code is written in jasmin
; assembly language. Though java does not allow field name overloading
; jvm allows the same.
; the code is equivalent to following pseudo java code
;
;
; ********************** NOT JAVA ***************************
;
; class of
; {
; static int x;
; static long x;
;
; public static void main(String[] args)
; {
; (int) x = 100; // assign 100 to int x
; (long) x = 1; // assign 1 to long x
; System.out.println((int)x);
; System.out.println((long)x);
;
; }
; }
;
;
;**********************************************************
.field static x I
.field static x J
.method static public main([Ljava/lang/String;)V
.limit stack 5
.limit locals 2
bipush 100
putstatic of/x I
lconst_1
putstatic of/x J
getstatic java/lang/System/out Ljava/io/PrintStream;
getstatic of/x I
invokevirtual java/io/PrintStream/println(I)V
getstatic java/lang/System/out Ljava/io/PrintStream;
getstatic of/x J
invokevirtual java/io/PrintStream/println(J)V
return
.end method
---------------------------------------------------------------------------
Both java and javap accept this class.
- duplicates
-
JDK-4790975 Java Generics Bridge methods conflict with VM spec 2.10.2
-
- Closed
-