Re: How do you get reference to an object from it's class name
i don't understand what you want to do.
if you know the type at runtime, you obviously cannot use it at compile time.
-------- Original-Nachricht --------
> Datum: Fri, 17 Aug 2012 05:39:42 -0700 (PDT)
> Von: Tim Nelson <tnelly27@...>
> An: scala-user@...
> CC: Tim Nelson <tnelly27@...>
> Betreff: Re: [scala-user] How do you get reference to an object from it\'s class name
> Hi,
>
> Thanks for the response, but I don't have the last bit to cast it to the
> type I need. If I had that I wouldn't need to do the rest of it, I could
> just reference my object directly. Without the cast it returns Object, but
> I need the real type. I guess this just isn't possible.
>
> Tim
>
> On Friday, August 17, 2012 2:04:47 AM UTC-5, nafg wrote:
> >
> > Try something like
> >
> Class.forName(theName).getField("MODULE$").get(null).asInstanceOf[MyObj.type]
> >
> >
> >
> > On Thu, Aug 16, 2012 at 4:33 PM, Tim Nelson
> <tnel...@...<javascript:>
> > > wrote:
> >
> >> Hi All,
> >>
> >> Say I have the following object:
> >>
> >> package code
> >>
> >> object MyObj {
> >> ...
> >> }
> >>
> >> Then, elsewhere, I have:
> >>
> >> val myobj = MyObj.getClass.getClassName
> >>
> >> Is there a way to get a reference to the actual MyObj object using the
> >> myobj String?
> >>
> >> The reason I need to do this is I have to pass the myobj String in a
> url
> >> param.
> >>
> >> Thanks,
> >> Tim
> >>
> >
> >