私はこの単純なスカラコードと相互運用しようとしていますが、いくつか問題があります。 Clojureのでclojure/scala interop?
package indicators
class DoubleRingBuffer(val capacity:Int=1000) {
var elements = new Array[Double](capacity);
private var head=capacity-1
private var max=0
def size():Int = {
return max+1
}
def add(obj:Double):Double = {
head-=1
if (head<0) head=capacity-1
return set(max+1,obj)
}
def set(i:Int,obj:Double):Double = {
System.out.println("HI")
if (i>=capacity || i<0)
throw new IndexOutOfBoundsException(i+" out of bounds")
if (i>=max) max=i
var index = (head+i)%capacity
var prev = elements(index)
elements(index)=obj
return prev
}
def get(i:Int=0):Double = {
System.out.println("size is "+size())
if (i>=size() || i<0)
throw new IndexOutOfBoundsException(i+" out of bounds")
var index = (head+i)%capacity
return elements(index)
}
}
、私はまたこの
(import 'indicators.DoubleRingBuffer)
(def b (DoubleRingBuffer. 100))
(pr (.size b)) ;;ERROR: No matching field found: size for class indicators.DoubleRingBuffer
(pr (.get b 33)) ;;returns 0: should throw an index out of bounds error!
(pr (.get b 100)) ;;throws index out of bounds error, as it should
を行う、私はコンソールに任意の出力を得ることはありません! scalaを使用してこのコードをテストすると、期待どおりに動作します。ここで何が起こっているのですか?clojureがscalaコードを使用できるように修正する方法はありますか?
ありがとうございました! Decompilingはトリック - Javaコードは完璧だったので、最終的に私のインクリメンタルビルドツールでは変なバグだった - 再起動し、期待通りに機能した! btw、私はhttp://java.decompiler.free.fr/、素晴らしいツールを使用します。 – josh
@josh: 'scalac -print'を試すこともできます。これはScalaの構文ではあるが、Javaと同形、つまりすべての高度なScalaの機能が削除された" desugared "バージョンを出力します。また、 'javap'のように動作する' scalap'、つまり '.class'ファイルを逆コンパイルします。 –
@josh:それがうまくいくのがうれしい! –