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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:16:27+00:00 2026-06-18T08:16:27+00:00

I have some problem to cast my objeсt Variable[A] where A <: Array[_] I

  • 0

I have some problem to cast my objeсt Variable[A] where A <: Array[_]

I create a function to compare manifest and cast data into Array to the good type.

My object Variable[A] store a Manifest[A] into the def 'type'

I make a plugin of an existent software, so it’s not me which instanciate this Variable with good type.

Prototype object and class :

object Prototype {
  def apply[T](n: String)(implicit t: Manifest[T]) = new Prototype[T] {
    val name = n
    val `type` = t
  }
}

trait Prototype[T] {
  def name: String
  def `type`: Manifest[T]
}

Variable Object and Class :

object Variable {
  def apply[T](p: Prototype[T], v: T) = new Variable[T] {
    val prototype = p
    val value = v
  }
}

trait Variable[T] {
  def prototype: Prototype[T]
  def value: T
}

My class which use :

class XYDataReader[A <: Array[_]](var data: Iterable[Variable[A]]) {

    def get[T](variable: Variable[A])(implicit m: Manifest[T]): Option[T] = {
        if (variable.prototype.`type` <:< m) {
          Some(variable.value.asInstanceOf[T])
        } else {
          None
        } 
}
}

There is probably a mistake of my part when i instanciate Variable object used to compare, so i give also the code of instanciation :

val v:List[Any] = List[Any](1.2,2,3)
val p = Prototype[Array[Any]]("col1")
val myVariable = Variable(p, v.toArray(ClassTag(p.`type`.runtimeClass)))

I don’t understand why pattern matching failed when i call get[Array[Double]](myVariable) where myVariable.value contain an Array[Double]

When i println() the two manifest :

  • variable array type : Array[double]
  • m type : Array[Double]

It seem an Array[Double] is not an Array[double], how can i resolve/cast 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-18T08:16:29+00:00Added an answer on June 18, 2026 at 8:16 am

    Finally, with help of colleague methods to resursively unArrayify Array, i resolve my runtime type reification problem. Now i can compare equality between Array[double] with Array[Double].

      // Convert unknow A en Array[T], so you need to call get with Type :
      // example : get[Array[Double](myVariable)
      // return an Array[Double] only if it's possible for this Variable, else it return None
      def get[T](variable: Variable[A])(implicit m: Manifest[T]): Option[T] = {
        if (ClassUtils.assignable(variable.prototype.`type`.runtimeClass, m.runtimeClass)) {
          val casted = variable.prototype.`type`.runtimeClass.cast(variable.value)
          Some(casted.asInstanceOf[T])
        } else {
          None
        }
    

    I hope these methods can help other people 🙂

    You can see helping method ClassUtils.assignable here :

    https://gist.github.com/4686167

    and on the source forge project :

    https://forge.iscpif.fr/projects/openmole/repository/revisions/master/entry/core/openmole/misc/org.openmole.misc.tools/src/main/scala/org/openmole/misc/tools/obj/ClassUtils.scala

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

Sidebar

Related Questions

We have some code that archives data from a Microsoft Access database into a
I have an object array that is being passed and then split up into
I have some problem converting my data from an plist to objects. The plist
I have some pointers to a base type of Shape. I want to compare
I have some problem to get the utf-8 string from PHP using jQuery $.load()
I have some problem with the cursor when using JOprionPane. I set a cursor
I have some problem. Dialog.dismiss() does not work. I want to input ip, username,
I have some problem with this mongoid. It's my first time to use mongoDB,
I have some problem with MySQL Workbench in that I sometimes can't set foreign
I have some problem in my JDBC code. I am trying to connect through

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.