2016-03-28 5 views
0

パフォーマンスベンチマークのためにScalaでGuava synchronizedQueueを初期化しようとしています。エラーのScalaのGoogle Guava synchronizedQueue初期化エラー

identifier expected but '[' found.

出典::。[INT]一部

class TestSynchronizedQueueJavaPTS { 
    private var assignedQForTest : java.util.Queue[Int] = null; 
    private var syncQueue : java.util.Queue[Int] = null; 

    def create(DS_Type : String) : java.util.concurrent.ConcurrentLinkedQueue[Int] ={ 
    DS_Type match{ 
     case "syncQueue" => 
     syncQueue = com.google.common.collect.Queues.synchronizedQueue(com.google.common.collect.MinMaxPriorityQueue.[Int]create()); 
     assignedQForTest = syncQueue; 
    } 
    assignedQForTest 
    } 
} 

は、しかし、私はこのエラーを取得しています。

import java.util.Queue; 
import com.google.common.collect.MinMaxPriorityQueue; 
import com.google.common.collect.Queues; 

public class test { 
    public static void main(String[] args) { 
     Queue<Integer> queue = Queues.synchronizedQueue(MinMaxPriorityQueue.<Integer>create()); 
     queue.add(15); 
     queue.add(63); 
     queue.add(20); 
     System.out.println (queue.poll()); 
     System.out.println (queue.poll()); 
    } 
} 

答えて

1

型paramは以下のようなメソッド名の後に行く必要があります。

は、私はエラーなしで完全に正常に動作している同等のJavaコードを持っています。その後、Scalaの IntComparableではないので、別のコンパイルエラーが発生します。私はそれを回避するために Integerに変更しましたが、多分あなたはその特定の問題を解決する別の方法を好むでしょう。

private var assignedQForTest : java.util.Queue[Integer] = null; 
    private var syncQueue : java.util.Queue[Integer] = null; 

    def create(DS_Type : String) : java.util.Queue[Integer] ={ 
    DS_Type match{ 
     case "syncQueue" => 
     syncQueue = com.google.common.collect.Queues.synchronizedQueue(com.google.common.collect.MinMaxPriorityQueue.create[Integer]()); 
     assignedQForTest = syncQueue; 
    } 
    assignedQForTest 
    } 
+0

ソルツ、動作しません。次のエラーが返されます: '◾typearguments [Int]は、valueのオーバーロードされた代替のどれにも合致しないcreate:[E <:Comparable [E]](x $ 1:Iterable [_ <:E])com .common.collect.MinMaxPriorityQueue [E] [E <:Comparable [E]] com.google.common.collect.MinMaxPriorityQueue [E] オーバーロードされたメソッド値の型パラメータの数が[ <:Comparable [E]](x $ 1:Iterable [_ <:E])com.google.common.collect.MinMaxPriorityQueue [E] [E <:Comparable [E]]()com.google.common.collect .MinMaxPriorityQueue [E] ' – Pranay

+0

つまり、構文上の誤りです。 – Pranay

+0

@Pranayあなたは私が言及した2番目の変更をしませんでした。「Int」を「Integer」に変更しました。また、私は 'Queue'を返すだけです。コードをコピー/ペーストしてチェックアウトするだけです – david