package test
case class UByte(val byte: Byte) extends AnyVal {
def ==(rhs: UByte): Boolean = byte == rhs.byte
}
class Test {
def test1(x: UByte, y: UByte): Boolean = x == y
def test2(x: UByte, y: Any): Boolean = x == y
def test3(x: Any, y: UByte): Boolean = x == y
def test4(x: Any, y: Any): Boolean = x == y
}
$ scalac test.scala
$ javap -c test.Test
public boolean test1(byte, byte);
Code:
0: getstatic #16 // Field test/UByte$.MODULE$:Ltest/UByte$;
3: iload_1
4: iload_2
5: invokevirtual #19 // Method test/UByte$.$eq$eq$extension:(BB)Z
8: ireturn
public boolean test2(byte, java.lang.Object);
Code:
0: new #28 // class test/UByte
3: dup
4: iload_1
5: invokespecial #32 // Method test/UByte."<init>":(B)V
8: aload_2
9: astore_3
10: dup
11: ifnonnull 22
14: pop
15: aload_3
16: ifnull 29
19: goto 33
22: aload_3
23: invokevirtual #36 // Method java/lang/Object.equals:(Ljava/lang/Object;)Z
26: ifeq 33
29: iconst_1
30: goto 34
33: iconst_0
34: ireturn
public boolean test3(java.lang.Object, byte);
Code:
0: aload_1
1: new #28 // class test/UByte
4: dup
5: iload_2
6: invokespecial #32 // Method test/UByte."<init>":(B)V
9: astore_3
10: dup
11: ifnonnull 22
14: pop
15: aload_3
16: ifnull 29
19: goto 33
22: aload_3
23: invokevirtual #36 // Method java/lang/Object.equals:(Ljava/lang/Object;)Z
26: ifeq 33
29: iconst_1
30: goto 34
33: iconst_0
34: ireturn
public boolean test4(java.lang.Object, java.lang.Object);
Code:
0: aload_1
1: aload_2
2: invokestatic #45 // Method scala/runtime/BoxesRunTime.equals:(Ljava/lang/Object;Ljava/lang/Object;)Z
5: ifeq 12
8: iconst_1
9: goto 13
12: iconst_0
13: ireturn