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 8044685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:18:13+00:00 2026-06-05T05:18:13+00:00

I have a Java class that takes a generic type parameter and a class

  • 0

I have a Java class that takes a generic type parameter and a class object related to that type:

public class Foo<T> {
    public Foo(Class<? extends T> type) {
    ...
    }
}

At first I thought I could make a clever wrapper for this in Scala:

class Bar[T](implicit m: Manifest[T]) {
    ...
    new Foo[T](m.erasure)
    ...
}

But this results in a compiler error similiar to this:

error: type mismatch;
found   : java.lang.Class[_$1(in value <local Bar>)] where type _$1(in value <local Bar>)
required: java.lang.Class[_ <: T] 
class Bar[T](implicit m: Manifest[T]) { new Foo[T](m.erasure) }

I think I understand why this happens, but is there any way I could get the correct type of class and make this code compile?

  • 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-05T05:18:14+00:00Added an answer on June 5, 2026 at 5:18 am

    How about m.erasure.asInstanceOf[Class[T]]?

    By the way, see this question for an explanation of why erasure returns Class[_] and not Class[T].

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

Sidebar

Related Questions

I have a simple Java class that has some methods: public class Utils {
I have a LoginActivity.java that imports VersionCheck.java. VersionCheck.java has a class VersionCheck that extends
In a java class I have a method that sometimes takes a long time
So I have a java class that takes individual commands and puts them into
I have a junit test method that takes a CommonsMultipartFile object as a parameter.
I'm currently working on Mangler's Android implementation. I have a java class that looks
I have a simple Java class that I need to serialize to be stored
I have a Java class MyPojo that I am interested in deserializing from JSON.
I am new to Java. I just read that class variables in Java have
If I have a class that implements java.lang.Runnable , there is technically nothing stopping

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.