Guice: How do I get an instance of a TypeLiteral-wrapped generic?

前端 未结 1 485
鱼传尺愫
鱼传尺愫 2020-12-31 03:06

I have a generic database access class, which i\'m binding using the TypeLiteral construct. Now in a test i want to mock that class and i have therefor created a Provider, t

相关标签:
1条回答
  • 2020-12-31 03:43

    Use Guice's Key facility, which is made for exactly this kind of problem. In your case

    injector.getInstance(Key.get(new TypeLiteral<GenericDbClass<Integer>>(){});
    

    will do the trick.

    0 讨论(0)
提交回复
热议问题