Scala

2016-03-28 18 views
0

için Google Guava synchronizedQueue başlatma hatası Performans karşılaştırma için Scala'da Guava synchronizedQueue başlatmaya çalışıyorum. HatanınScala

identifier expected but '[' found.

Kaynak:. [Uluslararası] bölüm

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 
    } 
} 

Ama bu hatayı alıyorum.

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()); 
    } 
} 

cevap

1

tip param aşağıda gibi yöntem adından sonra gitmeli:

herhangi hatasız kusursuz iyi çalışıyor eşdeğer Java Kod var. Daha sonra, Scala'nın Int Comparable olmadığı için başka bir derleme hatası var. Bunu anlamak için onu Integer olarak değiştirdim, ancak belki bu sorunu çözmenin farklı bir yolunu tercih edersiniz.

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

Sorrz, işe yaramıyor. Aşağıdaki hatayı verir: 'argümanları [Int], aşırı yüklenen alternatif değer alternatiflerinin hiçbirinin sınırlarına uymayın: [E <: Karşılaştırılabilir [E]] (x $ 1: Iterable [_ <: E]) com.google .common.collect.MinMaxPriorityQueue [E] [E <: Karşılaştırılabilir [E]]() com.google.common.collect.MinMaxPriorityQueue [E] overload aşırı yüklü yöntem değeri için yanlış tipte parametre sayısı alternatifler ile oluşturun: [E <: Karşılaştırılabilir [E]] (x $ 1: Tekrarlanabilir [_ <: E]) com.google.common.collect.MinMaxPriorityQueue [E] [E <: Karşılaştırılabilir [E]]() com.google.common.collect .MinMaxPriorityQueue [E] ' – Pranay

+0

Kısaca sözdizimsel hata. – Pranay

+0

@Pranay Ben bahsettiğim ikinci değişikliği yapmadım - Int '' Integer 'olarak değiştiriliyor. Ayrıca, sadece bir 'Queue' döndürüyorum. Sadece kodu kopyala/yapıştır ve kontrol et – david