0

I am trying to initialize Guava synchronizedQueue in Scala for performence benchmarking.

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

But I am getting this error:

identifier expected but '[' found.

Source of error: .[Int] part.

I have the equivalent Java Code which is working perfectly fine without any error:

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 Answer 1

1

The type param should go after the method name like below. Then, there is another compilation error since Scala's Int is not Comparable. I changed it to Integer to get around that, but maybe you will prefer a different way of resolving that particular issue.

  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
  }
Sign up to request clarification or add additional context in comments.

2 Comments

Sorrz, it does not work. Gives the following error: ◾type arguments [Int] conform to the bounds of none of the overloaded alternatives of value create: [E <: Comparable[E]](x$1: Iterable[_ <: E])com.google.common.collect.MinMaxPriorityQueue[E] <and> [E <: Comparable[E]]()com.google.common.collect.MinMaxPriorityQueue[E] ◾wrong number of type parameters for overloaded method value create with alternatives: [E <: Comparable[E]](x$1: Iterable[_ <: E])com.google.common.collect.MinMaxPriorityQueue[E] <and> [E <: Comparable[E]]()com.google.common.collect.MinMaxPriorityQueue[E]
@Pranay You didn't make the second change I mentioned -- changing Int to Integer. Also, I'm just returning a Queue. Just copy/paste the code and check it out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.