- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Converting a String/Name into a Type
Thu, 2009-06-11, 00:04
Howdy.
I'm struggling through the compiler code. I'm at a loss as to how to convert a string into a Type. For example, if I have "net.liftweb.util.Helpers", how do I get a Type instance the represents the class (assuming that a JAR containing the class is on the classpath)?
Thanks,
David
--
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
I'm struggling through the compiler code. I'm at a loss as to how to convert a string into a Type. For example, if I have "net.liftweb.util.Helpers", how do I get a Type instance the represents the class (assuming that a JAR containing the class is on the classpath)?
Thanks,
David
--
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
Thu, 2009-06-11, 00:47
#2
Re: Converting a String/Name into a Type
On Wed, Jun 10, 2009 at 4:26 PM, Paul Phillips <paulp@improving.org> wrote:
On Wed, Jun 10, 2009 at 04:04:18PM -0700, David Pollak wrote:
> I'm struggling through the compiler code. I'm at a loss as to how to
> convert a string into a Type. For example, if I have
> "net.liftweb.util.Helpers", how do I get a Type instance the
> represents the class (assuming that a JAR containing the class is on
> the classpath)?
Look at Definitions for examples.
// that is a Symbol
lazy val CharSequenceClass = getClass("java.lang.CharSequence")
Well crap, I'm an idiot. I was trying to create a Name and pass a name to getClass... that failed... but the String, the String... it worked. Sorry for being really frickin' stupid.
// this would be a type
CharSequenceClass.tpe
Of course the usual caveats (about how there might be lots of other
stuff one ought to do) apply.
--
Paul Phillips | A national political campaign is better than the
Everyman | best circus ever heard of, with a mass baptism and
Empiricist | a couple of hangings thrown in.
i pull his palp! | -- H. L. Mencken
--
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
On Wed, Jun 10, 2009 at 04:04:18PM -0700, David Pollak wrote:
> I'm struggling through the compiler code. I'm at a loss as to how to
> convert a string into a Type. For example, if I have
> "net.liftweb.util.Helpers", how do I get a Type instance the
> represents the class (assuming that a JAR containing the class is on
> the classpath)?
Look at Definitions for examples.
// that is a Symbol
lazy val CharSequenceClass = getClass("java.lang.CharSequence")
// this would be a type
CharSequenceClass.tpe
Of course the usual caveats (about how there might be lots of other
stuff one ought to do) apply.