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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:30:02+00:00 2026-05-23T13:30:02+00:00

Is it possible to have a manifest defined based on another manifest in Scala?

  • 0

Is it possible to have a manifest defined based on another manifest in Scala?

I’ve pretty much resigned myself to the belief that this is not possible because the Scala Manifest information was not intended to be used dynamically.

Here’s the problem. I have a function that can return more than one type of object (String, Int, List[Int], List[List[String]], etc.) To support these multiple types, the return type is set to Any, but due to type erasure the information about the types supported in Lists, Maps, etc is lost. In an attempt to recover some of the details, I return a Manifest along with the return type.

However, the returned information may then be placed in another list or map and that is then returned from another function. I want to update the manifest to include the fact that the type is now a List or Map of the previous type as defined by the manifest.

Here’s some example code

def returnWithManifest[T: Manifest](x: T) = (x, manifest[T])

// May return String, Int, List[Int], List[List[String]], ...
def contrivedExample(t: String): (Any, Manifest[_]) = t match {
  case "String" => returnWithManifest("test")
  case "Int" => returnWithManifest(1)
  case "Boolean" => returnWithManifest(true)
  case "List[Int]" => returnWithManifest(List(1,2,3))
  case "List[List[String]]" => 
    returnWithManifest(List(List("a","b"),List("c","d")))
  case _ => returnWithManifest(None)
}

scala> val v1 = contrivedExample("List[Int]")
v1: (Any, Manifest[_]) = (List(1, 2, 3),scala.collection.immutable.List[Int])

scala> val x = v1._1
x: Any = List(1, 2, 3)

scala> val m = v1._2
m: scala.reflect.Manifest[_] = scala.collection.immutable.List[Int]

scala> val v2 = List(x)
v2: List[Any] = List(List(1, 2, 3))

From the manifest of ‘v1’ I know that v1 is of type List[Int] so when I create ‘v2’ I should have all the information I need to create a manifest identifying that the type is List[List[Int]], but instead I only have List[Any] to work with. Perhaps syntax like the following:

val v2: m = List(x)
val v2 = List[m](x)

I realize it looks like I’m trying to define a type dynamically, but in reality the information is metadata related to type erasure of statically known types. I guess if this can be solved, then type erasure can be solved. However, at the very least I thought I should be able to do something like:

scala> val m2 = m.wrapInList()
m2: scala.reflect.Manifest[_] = 
      scala.collection.immutable.List[scala.collection.immutable.List[Int]]
  • 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-23T13:30:03+00:00Added an answer on May 23, 2026 at 1:30 pm

    Edit: Adriaan Moors is right pointing out this works:

    def makeListManifest[T: Manifest] = manifest[List[T]]
    

    You’ll just have to call it explicitly, passing it the manifest you have obtained.


    My old answer:

    huynhjl is partially right: currently this won’t work automatically. We’d need the compiler to be smart enough to compile this:

    def makeListManifest[T](m: Manifest[T]) = manifest[List[T]]
    

    without any extra implicit parameter. While it certainly looks feasible (all the needed info is here), it isn’t implemented yet (2.9.0.1), as I believe manifests are now either inserted locally if the compiler has all the static type info it needs or looked up in the implicit scope, but not generated from other (possibly implicitly available) manifests.

    What you can do, however, is construct that manifest yourself with the methods on the companion object:

    scala> import reflect.Manifest
    scala> Manifest.classType(classOf[List[_]], manifest[Int])
    res0: scala.reflect.Manifest[List[_]] = scala.collection.immutable.List[Int]
    

    So you can implement makeListManifest yourself:

    scala> def makeListManifest[T](m: Manifest[T]) = Manifest.classType(classOf[List[_]], m)            
    makeListManifest: [T](m: scala.reflect.Manifest[T])scala.reflect.Manifest[List[_]]
    

    Note that although the right manifest will be returned, the static return type of makeListManifest is only Manifest[List[_]]. But you could safely cast to Manifest[List[T]] here.

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

Sidebar

Related Questions

I have an application that runs using as AsInvoker manifest, this uses ProcessStartInfo to
Is it possible to have a free iPhone app that has say an initial
Is it possible to have an argument parser like this? import argparse parser.add_argument('query2target.bam', help='A
I have some applications (some native, some .NET) which use manifest files so that
I have a (COM Interop based) ActiveX contol that I am trying to use
I have a C# project with many classes. Is it possible to pack this
Say I have a simple appcache manifest that looks like: CACHE: # v1 #
Possible Duplicate: My HTML5 Application Cache Manifest is caching everything I have made an
Is it possible in Android to capture screen rotate events but not actually have
Is it possible too have a manifest file with directory strings, fx. #css SomeDIR/crap0.css

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.