This page is no longer maintained — Please continue to the home page at www.scala-lang.org

implicit type information

1 reply
efleming969
Joined: 2009-01-04,
User offline. Last seen 3 years 22 weeks ago.
I've learned to use the Manifest type for getting parametrized type information, but I can't do the following:

class MyType {
    val foo: String = "hello"
}

class MyService {

    def bar[T](implicit m: scala.reflect.Manifest[T]): Unit = {
        println(m.erasure)
    }
}

class MyProvider[T] {

    val s = new MyService

    def foo(): Unit = {
        s.bar[T]
    }
}

object ParameterTypes {

    def main(args: Array[String]): Unit = {
       
        val p = new MyProvider[MyType]

        p.foo
    }
}

I realize the Manifest type is experimental, but this type of parametrization seem really useful.  Any suggestions?
David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: implicit type information
class MyProvider[T](implicit m: scala.reflect.Manifest[T]) {
    val s = new MyService
    def foo(): Unit = {        s.bar[T]    }}
class MyService {
    def bar[T](implicit m: scala.reflect.Manifest[T]): Unit = {        println(m.erasure)    }}
Just make sure that you have a manifest before T gets erased.
On Sun, Jan 4, 2009 at 1:46 AM, Erick Fleming <efleming969 [at] gmail [dot] com> wrote:
I've learned to use the Manifest type for getting parametrized type information, but I can't do the following:

class MyType {
    val foo: String = "hello"
}

class MyService {

    def bar[T](implicit m: scala.reflect.Manifest[T]): Unit = {
        println(m.erasure)
    }
}

class MyProvider[T] {

    val s = new MyService

    def foo(): Unit = {
        s.bar[T]
    }
}

object ParameterTypes {

    def main(args: Array[String]): Unit = {
       
        val p = new MyProvider[MyType]

        p.foo
    }
}

I realize the Manifest type is experimental, but this type of parametrization seem really useful.  Any suggestions?



--
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland