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

  • Home
  • SEARCH
  • 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 7865549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:07:25+00:00 2026-06-03T00:07:25+00:00

I made some simplifications of my original code just to focus on the problem.

  • 0

I made some simplifications of my original code just to focus on the problem.

I have this set of classes:

abstract class A(n: String){
   def name = n
}

abstract class B[T](n: String) extends A(n){
   def printT(t: T) = println(t)
}

object B{
   def unapply[T](b: B[T]) = Some(b.name)
}

case class C extends B[Int]("integer")

Now I want to discover on a List of As what extends B and then use printT. Something like this:

val list = List(C)

list match{
   case b @ B(_) => b.printT(2) 
}

On the line case b @ B(_) => b.printT(2) I got:

found   : Int(2)
required: T where type T
case b @ B(_) => b.printT(2)
                              ^

Probly this problem would be solved if I could associate the T on the object that I want to use the T of the class. Any way to solve this?

  • 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-06-03T00:07:26+00:00Added an answer on June 3, 2026 at 12:07 am

    There are a few things wrong with your code.

    1) Case classes should be declared with a parameter list: case class C()

    2) To instantiate a C, you need to write C(). List(C) is a List[C.type] but List(C()) is a List[C], which is what you want.

    3) list match doesn’t make sense if your case is a B: list is a List, so it can never be a B. Perhaps you meant list foreach, which will do the match on each element in the list?

    Here’s a corrected version of your code that prints 2 as expected.

    case class C() extends B[Int]("integer")
    
    val list = List(C())
    
    list foreach {
      case b @ B(_) => b.printT(2)
    }
    

    Additionally, the b @ B(_) syntax looks a bit weird to me since there’s no point in extracting B if you’re not going to use its parts. You could, instead, just match on the type:

    list foreach {
      case b: B[Int] => b.printT(2)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made some code to do this, but as It doesn't work. I
I have made some progress with the DataList and UserControl this morning but I
I made some classes using xjc. public class MyType { @XmlElementRefs({ @XmlElementRef(name = MyInnerType,
I have made some code that makes powerpoint and excel work together. And I
I have made some progress on the problem I posted about yesterday, so I
I made some javascript code for my website, it works without problem on opera
I have made some code that creates a red border around an image when
I have made some c code for a program, which does some psycho-acoustics on
I made some code, for understanding the concept/basic of pointer: int a=1; int *b=&a;
It made some errors like this: KDnsCache.cpp: In member function ‘unsigned int KDnsCache::GetName(const char*)’:

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.