Created
September 22, 2017 15:32
-
-
Save rudogma/5f97030ab44d77e71354f025eac161bf to your computer and use it in GitHub Desktop.
Difference between Newtype and TaggedType
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- package.scala -- | |
object Booter extends TaggedType[Int] | |
type Booter = Booter.Type | |
implicit class StepOps(val __v:Int) { | |
def next:Step = Step @@ (__v + 1) | |
def +(v2:Int):Step = Step @@ (__v + v2) | |
} | |
object Step extends NewType[Int, StepOps] | |
type Step = Step.NewType | |
-- Chocker.scala -- | |
// Boxing operations and boilerplate for booter0 will be optimized by JIT, | |
// but I saw nowhere information that it can move Object to primitive | |
class Choker { | |
val step0:Step = Step(5) | |
val booter0:Booter = Booter(6) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Choker { | |
public java.lang.Object step0(); | |
Code: | |
0: aload_0 | |
1: getfield #31 // Field step0:Ljava/lang/Object; | |
4: areturn | |
public int booter0(); | |
Code: | |
0: aload_0 | |
1: getfield #36 // Field booter0:I | |
4: ireturn | |
public Choker(); | |
Code: | |
0: aload_0 | |
1: invokespecial #40 // Method java/lang/Object."<init>":()V | |
4: aload_0 | |
5: getstatic #44 // Field package$Step$.MODULE$:L/package$Step$; | |
8: iconst_5 | |
9: invokestatic #50 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer; | |
12: getstatic #53 // Field supertagged/package$Tagger$.MODULE$:Lsupertagged/package$Tagger$; | |
15: invokevirtual #57 // Method supertagged/package$Tagger$.baseRaw:()Lsupertagged/package$Tagger; | |
18: invokevirtual #61 // Method package$Step$.apply:(Ljava/lang/Object;Lsupertagged/package$Tagger;)Ljava/lang/Object; | |
21: putfield #31 // Field step0:Ljava/lang/Object; | |
24: aload_0 | |
25: getstatic #64 // Field package$Booter$.MODULE$:Lpackage$Booter$; | |
28: bipush 6 | |
30: invokestatic #50 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer; | |
33: getstatic #53 // Field supertagged/package$Tagger$.MODULE$:Lsupertagged/package$Tagger$; | |
36: invokevirtual #57 // Method supertagged/package$Tagger$.baseRaw:()Lsupertagged/package$Tagger; | |
39: invokevirtual #65 // Method package$Booter$.apply:(Ljava/lang/Object;Lsupertagged/package$Tagger;)Ljava/lang/Object; | |
42: invokestatic #69 // Method scala/runtime/BoxesRunTime.unboxToInt:(Ljava/lang/Object;)I | |
45: putfield #36 // Field booter0:I | |
48: return | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment