Last active
November 24, 2020 13:28
-
-
Save xuwei-k/0d38828eb5f0c94eb23c9982589a068b to your computer and use it in GitHub Desktop.
"higher kind" and "parameter list"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
libraryDependencies += "com.google.inject" % "guice" % "4.2.3" | |
scalaVersion := "2.13.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ javap target/scala-3.0.0-M1/classes/example/B1.class | |
Compiled from "Main.scala" | |
public class example.B1 { | |
public example.B1(java.lang.String, example.A<scala.collection.immutable.List<java.lang.Object>>); | |
} | |
$ javap target/scala-3.0.0-M1/classes/example/B2.class | |
Compiled from "Main.scala" | |
public class example.B2 { | |
public example.B2(java.lang.String, example.A<scala.collection.immutable.List<java.lang.Object>>); | |
} | |
$ javap target/scala-2.13/classes/example/B2.class | |
Compiled from "Main.scala" | |
public class example.B2 { | |
public example.B2(java.lang.String, example.A<?>); | |
} | |
$ javap target/scala-2.13/classes/example/B1.class | |
Compiled from "Main.scala" | |
public class example.B1 { | |
public example.B1(java.lang.String, example.A<scala.collection.immutable.List>); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example | |
import com.google.inject.AbstractModule | |
import com.google.inject.Guice | |
import com.google.inject.TypeLiteral | |
import javax.inject.Inject | |
// javap (Scala 2.13) | |
// public example.B1(java.lang.String, example.A<scala.collection.immutable.List>); | |
class B1 @Inject() (x: String, y: A[List]) | |
// javap (Scala 2.13) | |
// public example.B2(java.lang.String, example.A<?>); | |
class B2 @Inject() (x: String)(y: A[List]) | |
trait A[B[_]] | |
object AInstance extends A[List] | |
class Module1 extends AbstractModule { | |
override def configure(): Unit = { | |
bind(new TypeLiteral[A[List]]() {}).toInstance(AInstance) | |
bind(classOf[B1]) | |
} | |
} | |
class Module2 extends AbstractModule { | |
override def configure(): Unit = { | |
bind(new TypeLiteral[A[List]]() {}).toInstance(AInstance) | |
bind(classOf[B2]) | |
} | |
} | |
object Main { | |
def main(args: Array[String]): Unit = { | |
try { | |
val injector = Guice.createInjector(new Module1()) | |
injector.getInstance(classOf[B1]) | |
println("success B1") | |
} catch { | |
case e: Throwable => | |
println("fail B1") | |
println(e) | |
} | |
try { | |
val injector = Guice.createInjector(new Module2()) | |
injector.getInstance(classOf[B2]) | |
println("success B2") | |
} catch { | |
case e: Throwable => | |
println("fail B2") | |
println(e) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
success B1 | |
fail B2 | |
com.google.inject.CreationException: Unable to create injector, see the following errors: | |
1) No implementation for example.A<?> was bound. | |
while locating example.A<?> | |
for the 2nd parameter of example.B2.<init>(Main.scala:16) | |
at example.Module2.configure(Main.scala:29) | |
1 error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[info] running example.Main | |
11 24, 2020 5:12:59 午後 com.google.inject.internal.MessageProcessor visit | |
情報: An exception was caught and reported. Message: java.lang.RuntimeException: Missing type parameter. | |
java.lang.RuntimeException: Missing type parameter. | |
at com.google.inject.TypeLiteral.getSuperclassTypeParameter(TypeLiteral.java:95) | |
at com.google.inject.TypeLiteral.<init>(TypeLiteral.java:75) | |
at example.Module1$$anon$1.<init>(Main.scala:21) | |
at example.Module1.configure(Main.scala:21) | |
at com.google.inject.AbstractModule.configure(AbstractModule.java:61) | |
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:347) | |
at com.google.inject.spi.Elements.getElements(Elements.java:104) | |
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137) | |
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:105) | |
at com.google.inject.Guice.createInjector(Guice.java:87) | |
at com.google.inject.Guice.createInjector(Guice.java:69) | |
at com.google.inject.Guice.createInjector(Guice.java:59) | |
at example.Main$.main(Main.scala:36) | |
at example.Main.main(Main.scala) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:498) | |
at sbt.Run.invokeMain(Run.scala:133) | |
at sbt.Run.execute$1(Run.scala:82) | |
at sbt.Run.$anonfun$runWithLoader$5(Run.scala:110) | |
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) | |
at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17) | |
at sbt.TrapExit$App.run(TrapExit.scala:258) | |
at java.lang.Thread.run(Thread.java:748) | |
fail B1 | |
com.google.inject.CreationException: Unable to create injector, see the following errors: | |
1) An exception was caught and reported. Message: Missing type parameter. | |
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137) | |
1 error | |
11 24, 2020 5:12:59 午後 com.google.inject.internal.MessageProcessor visit | |
情報: An exception was caught and reported. Message: java.lang.RuntimeException: Missing type parameter. | |
java.lang.RuntimeException: Missing type parameter. | |
at com.google.inject.TypeLiteral.getSuperclassTypeParameter(TypeLiteral.java:95) | |
at com.google.inject.TypeLiteral.<init>(TypeLiteral.java:75) | |
at example.Module2$$anon$1.<init>(Main.scala:28) | |
at example.Module2.configure(Main.scala:28) | |
at com.google.inject.AbstractModule.configure(AbstractModule.java:61) | |
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:347) | |
at com.google.inject.spi.Elements.getElements(Elements.java:104) | |
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137) | |
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:105) | |
at com.google.inject.Guice.createInjector(Guice.java:87) | |
at com.google.inject.Guice.createInjector(Guice.java:69) | |
at com.google.inject.Guice.createInjector(Guice.java:59) | |
at example.Main$.main(Main.scala:46) | |
at example.Main.main(Main.scala) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:498) | |
at sbt.Run.invokeMain(Run.scala:133) | |
at sbt.Run.execute$1(Run.scala:82) | |
at sbt.Run.$anonfun$runWithLoader$5(Run.scala:110) | |
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) | |
at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17) | |
at sbt.TrapExit$App.run(TrapExit.scala:258) | |
at java.lang.Thread.run(Thread.java:748) | |
fail B2 | |
com.google.inject.CreationException: Unable to create injector, see the following errors: | |
1) An exception was caught and reported. Message: Missing type parameter. | |
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137) | |
1 error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment