Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 996931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:57:10+00:00 2026-05-16T06:57:10+00:00

Here is a snippet of the code- import java.util.concurrent.LinkedBlockingQueue def main(args:Array[String]) { val queue=new

  • 0

Here is a snippet of the code-

import java.util.concurrent.LinkedBlockingQueue  

def main(args:Array[String]) {  
    val queue=new LinkedBlockingQueue  
    queue.put("foo")  
}

This gives me –

error: type mismatch;
found : java.lang.String(“foo”)
required: Nothing
queue.add(“foo”)

My understanding is its because of me not specifying the type of the elements going into the queue. If thats the case, how do we specify types in scala for the LinkedBlockingQueue instead of the default generic ones?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:57:11+00:00Added an answer on May 16, 2026 at 6:57 am

    When you don’t supply a type signature but one is needed, Scala uses the most restrictive signature possible. Since Nothing is the most restrictive of all (nothing can be Nothing!), Scala chooses LinkedBlockingQueue[Nothing].

    But in this case, the restrictiveness means that you can’t actually put anything into this highly-restrictive queue.

    As you’ve already discovered, the solution is to specify the type of classes in the collection:

    val queue = new LinkedBlockingQueue[String]
    

    But note that the type inferencer can figure out the right type in other cases by following the “as restrictive as possible” rule. For example if initial is another Java collection that is typed as containing strings,

    val queue = new LinkedBlockingQueue(initial)
    

    would just work, as it would read off the String type from initial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the code snippet: public static void main (String[]arg) { char ca = 'a'
Let's look at the following code snippet in Java. package demo; import java.util.Calendar; final
I have this code snippet import java.util.ArrayList; import java.util.List; public class AssertTest { public
Here's the code snippet: import java.awt.BorderLayout; import java.awt.HeadlessException; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton;
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
Here is a snippet of my code: import Control.Monad.State as S get x =
Here 's my code snippet import gtk, webkit window = gtk.Window() browser = webkit.WebView()
Here's a snippet of code I saw on the web and I'm wondering if
Here is my code snippet where I'am taking confidence with initialization blocks class Father{
Here is the following code-snippet I'm using in my Google Spreadsheet onEdit() function: else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.