6. 単純なクラスの例 (gen-class)
Example (bar.clj)
1 (gen-class
2 :name Bar
3 :methods [[inc [long] long ]])
4
5 (defn- -inc ^long
6 [^long x]
7 (inc x))
Example (Foo.java)
1 class Foo {
2 public long inc(long x) {
3 return x + 1;
4 }
5 }
7. javap の実行例
Example (javap Bar)
1 public class Bar {
2 public static {};
3 public Bar();
4 public java.lang.Object
clone ();
5 public int hashCode ();
6 public java.lang.String
toString ();
7 public boolean equals(java
.lang.Object );
8 public long inc(long);
9 }
8. javap の実行例
Example (javap Bar)
1 public class Bar {
2 public static {};
3 public Bar();
4 public java.lang.Object
clone ();
5 public int hashCode ();
6 public java.lang.String
toString ();
7 public boolean equals(java
.lang.Object );
8 public long inc(long);
9 }
Example (javap Foo)
1 Compiled from "Foo.java"
2 class Foo {
3 Foo();
4 public long inc(long);
5 }
9. 身に覚えの無いメソッド (1/2)
_人人人人人人人人人人人人人人_
> clone(); <
> hashCode(); <
> toString(); <
> equals(java.lang.Object); <
 ̄YYYYYYYYYYYYYY ̄
Example (bar.clj)
1 (gen-class
2 :name Bar
3 :methods [[inc [long] long ]])
10. 身に覚えなの無いメソッド (2/2)
1 user > (.clone (Bar.))
2 CloneNotSupportedException Bar java.lang.Object.clone (
Object.java:-2)
3
4 user > (. hashCode (Bar.))
5 1332407210
6
7 user > (. toString (Bar.))
8 "Bar@4ce58390"
9
10 user > (. equals (Bar.) (Bar.))
11 false
12. gen-class の仕様
clone() がつくられるのは gen-class の仕様
docstring (:methods)
The generated class automatically defines all of the
non-private methods of its superclasses/interfaces.
生成クラスにはスーパークラスおよび実装インタフェースのプラ
イベードではないメソッドが自動的に定義される。
13. gen-class の仕様
clone() がつくられるのは gen-class の仕様
docstring (:methods)
The generated class automatically defines all of the
non-private methods of its superclasses/interfaces.
生成クラスにはスーパークラスおよび実装インタフェースのプラ
イベードではないメソッドが自動的に定義される。
docstring (:extends)
14. gen-class の仕様
clone() がつくられるのは gen-class の仕様
docstring (:methods)
The generated class automatically defines all of the
non-private methods of its superclasses/interfaces.
生成クラスにはスーパークラスおよび実装インタフェースのプラ
イベードではないメソッドが自動的に定義される。
docstring (:extends)
Specifies the superclass, the non-private methods of
which will be overridden by the class. If not provided,
defaults to Object.
スーパークラスが :extends で明示的に指定されない場合のデ
フォルトは Object.
34. Static Initializer (3/3)
Example (Java)
1 Var.internPrivate("example", "-inc");
Example (Clojure)
1 example /-inc
スタティックフィールドの中身
関数(メソッドの処理を担当)の Var をキャッシュ