Created
June 23, 2011 10:57
-
-
Save xuwei-k/1042348 to your computer and use it in GitHub Desktop.
Pimp my Library するときの違いについて
This file contains hidden or 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
import java.awt.Point | |
object Test1{ | |
implicit def toRichPoint(p:Point) = new RichPoint(p.x,p.y) | |
class RichPoint(x:Int,y:Int){ | |
def +(other:Point) = new Point( this.x + other.x , this.y + other.y ) | |
} | |
val a = new Point(1,2) + new Point(3,4) | |
} | |
object Test2{ | |
implicit def toRichPoint(p:Point) = new{ | |
def +(other:Point) = new Point( p.x + other.x , p.y + other.y ) | |
} | |
val a = new Point(1,2) + new Point(3,4) | |
} |
This file contains hidden or 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
import java.awt.Point; | |
import scala.ScalaObject; | |
public final class Test1$ | |
implements ScalaObject | |
{ | |
public Test1.RichPoint toRichPoint(Point p) | |
{ | |
return new Test1.RichPoint(p.x, p.y); | |
} | |
public Point a() | |
{ | |
return a; | |
} | |
private Test1$() | |
{ | |
} | |
public static final Test1$ MODULE$ = this; | |
private final Point a = toRichPoint(new Point(1, 2)).$plus(new Point(3, 4)); | |
static | |
{ | |
new Test1$(); | |
} | |
} |
This file contains hidden or 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
import java.awt.Point; | |
import scala.ScalaObject; | |
public final class Test1 | |
{ | |
public static class RichPoint | |
implements ScalaObject | |
{ | |
public Point $plus(Point other) | |
{ | |
return new Point(x + other.x, y + other.y); | |
} | |
private final int x; | |
private final int y; | |
public RichPoint(int x, int y) | |
{ | |
this.x = x; | |
this.y = y; | |
super(); | |
} | |
} | |
public static final Point a() | |
{ | |
return Test1$.MODULE$.a(); | |
} | |
public static final RichPoint toRichPoint(Point point) | |
{ | |
return Test1$.MODULE$.toRichPoint(point); | |
} | |
} |
This file contains hidden or 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
import java.awt.Point; | |
import java.lang.ref.SoftReference; | |
import java.lang.reflect.InvocationTargetException; | |
import java.lang.reflect.Method; | |
import scala.ScalaObject; | |
import scala.runtime.EmptyMethodCache; | |
import scala.runtime.MethodCache; | |
public final class Test2$ | |
implements ScalaObject | |
{ | |
public static Method reflMethod$Method1(Class class1) | |
{ | |
if((MethodCache)reflPoly$Cache1.get() == null) | |
reflPoly$Cache1 = new SoftReference(new EmptyMethodCache()); | |
Method method1 = ((MethodCache)reflPoly$Cache1.get()).find(class1); | |
if(method1 == null) | |
{ | |
method1 = class1.getMethod("$plus", reflParams$Cache1); | |
method1.setAccessible(true); | |
reflPoly$Cache1 = new SoftReference(((MethodCache)reflPoly$Cache1.get()).add(class1, method1)); | |
return method1; | |
} else | |
{ | |
return method1; | |
} | |
} | |
public Object toRichPoint(Point p$1) | |
{ | |
return new anon._cls1(p$1); | |
} | |
public Point a() | |
{ | |
return a; | |
} | |
private Test2$() | |
{ | |
MODULE$ = this; | |
this; | |
Object qual1; | |
Object exceptionResult1; | |
qual1 = toRichPoint(new Point(1, 2)); | |
exceptionResult1 = null; | |
(Point)(Point)(exceptionResult1 = reflMethod$Method1(qual1.getClass()).invoke(qual1, new Object[] { | |
new Point(3, 4) | |
})); | |
a; | |
return; | |
InvocationTargetException invocationtargetexception; | |
invocationtargetexception; | |
throw invocationtargetexception.getCause(); | |
} | |
public static final Test2$ MODULE$; | |
private final Point a; | |
private static final Class reflParams$Cache1[] = { | |
java/awt/Point | |
}; | |
private static volatile SoftReference reflPoly$Cache1 = new SoftReference(new EmptyMethodCache()); | |
static | |
{ | |
new Test2$(); | |
} | |
} |
This file contains hidden or 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
import java.awt.Point; | |
public final class Test2 | |
{ | |
public static final Point a() | |
{ | |
return Test2$.MODULE$.a(); | |
} | |
public static final Object toRichPoint(Point point) | |
{ | |
return Test2$.MODULE$.toRichPoint(point); | |
} | |
// Unreferenced inner class Test2$$anon$1 | |
public static final class .anon._cls1 | |
{ | |
public Point $plus(Point other) | |
{ | |
return new Point(p$1.x + other.x, p$1.y + other.y); | |
} | |
private final Point p$1; | |
public .anon._cls1(Point point) | |
{ | |
p$1 = point; | |
super(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment