Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created April 1, 2022 15:58
Show Gist options
  • Save kmizu/040d1517a0cf30dbfed82bea7cad7c27 to your computer and use it in GitHub Desktop.
Save kmizu/040d1517a0cf30dbfed82bea7cad7c27 to your computer and use it in GitHub Desktop.
戻り値型だけが違うメソッドをJVM上で呼び分ける
C:\Users\Mizushima>type DifferentReturnTypes.j
.class public DifferentReturnTypes
.super java/lang/Object
;
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
.method public static foo()I
.limit stack 1
bipush 1
ireturn
.end method
.method public static foo()Ljava/lang/String;
.limit stack 1
ldc "Hello"
areturn
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 2
.limit locals 2
getstatic java/lang/System/out Ljava/io/PrintStream;
invokestatic DifferentReturnTypes/foo()I
invokevirtual java/io/PrintStream/println(I)V
getstatic java/lang/System/out Ljava/io/PrintStream;
invokestatic DifferentReturnTypes/foo()Ljava/lang/String;
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
return
.end method
C:\Users\Mizushima>java -jar c:\dev\jasmin-2.4\\jasmin.jar DifferentReturnTypes.j
Generated: DifferentReturnTypes.class
C:\Users\Mizushima>java DifferentReturnTypes
1
Hello
.class public DifferentReturnTypes
.super java/lang/Object
;
; standard initializer
.method public <init>()V
aload_0
invokenonvirtual java/lang/Object/<init>()V
return
.end method
; public static int foo()
.method public static foo()I
.limit stack 1
bipush 1
ireturn
.end method
; public static String foo()
.method public static foo()Ljava/lang/String;
.limit stack 1
ldc "Hello"
areturn
.end method
.method public static main([Ljava/lang/String;)V
.limit stack 2
.limit locals 2
getstatic java/lang/System/out Ljava/io/PrintStream;
invokestatic DifferentReturnTypes/foo()I
invokevirtual java/io/PrintStream/println(I)V
getstatic java/lang/System/out Ljava/io/PrintStream;
invokestatic DifferentReturnTypes/foo()Ljava/lang/String;
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
return
.end method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment