Skip to content

does not bind AnyVal properly... #49

@shengc

Description

@shengc

This throws java.lang.reflect.MalformedParameterizedTypeException. I think the problem is Guice depends on Java reflection which cannot properly interpret AnyVal, as I cannot assign null to the initial value of Foo in BarProvider, since Foo is not bounded by Null

class Foo(val foo: String) extends AnyVal {}
object Foo {
  def apply(foo: String): Foo = new Foo(foo)

  def empty: Foo = new Foo("")
}

import com.google.inject._
import net.codingwell.scalaguice._

class BarProvider extends Provider[String] {
  @Inject val foo: Foo = Foo.empty

  def get() = foo.toString()
}

class Module extends AbstractModule with ScalaModule {
  def configure() {
    bind[Foo].toInstance(Foo("abc"))
    bind[String].toProvider[BarProvider]
  }
}

import net.codingwell.scalaguice.InjectorExtensions._

val injector = Guice.createInjector(new Module)
Console.println(injector.instance[String])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions