Howdy,
Scala is a static language, so the class for casting must be known at
compile time.  It's not possible to construct a String at runtime and cast
an object into a class represented by that String.

However, casting to a known class is easy in Scala... and it's done
primarily using pattern matching.  The following code:

  def foo(in: Any) = in match {
    case mm: MetaMapper[_] =>
      mm.findAll.map(
        (m: Mapper[_]) =>
        m.asJs
      )
    case _ =>
  }


Does what I think you want.  It takes an incoming instance, in and matches
it against being an instance of MetaMapper[_].  This means its some type of
MetaMapper (we don't know or care what the type parameter is).  If it is a
MetaMapper, it's assigned to the mm variable.  We can then call findAll on
that variable and we have a bunch of Mapper[_] instances.  Note that I
explicitly called out the type of m in the function, but that line could be
re-written mm.findAll.map(m => m.asJs) because the compiler infers the type
of m.

Does this help?

Thanks,

David


On Thu, Apr 9, 2009 at 3:55 AM, Amit Kumar Verma <cdac.a...@gmail.com>wrote:

>
> Hi All,
>
> I am trying to type cast an scala object to its mapper object
>
> 1     def getJSONString(anyObject :Object):NodeSeq = {
>
> 2             var obj = anyObject.asInstanceOf[anyObject.getClass
> ().getName()];
>
> 3             obj.findAll.map(userdetails => {
>                    // some code will go here
>             }
>             Text("any string")
>      }
>
>
> but i am getting erroe as "expected [ but found (" on line 2.
>
> please help me to typecast the object to its mapper object.
>
> Thanks
> Amit Kumar Verma
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to