google / google/guice

ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to javax.inject.Provider

Open
#1,281 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

Hello there,

We created a binding using toProvider()

bind(ProvidedClass.class).annotatedWith(Names.named("providedClass")).toProvider(ClassProvider.class).in(Singleton.class);

While creating Injector the following error happens:

java.lang.ClassCastException: com.sun.proxy.$Proxy11 cannot be cast to javax.inject.Provider
at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:60)

What is wrong with it?

I also tried to get class instance through:

ProvidedClass providedClass = injector.getInstance(Key.get(ProvidedClass.class, Names.named("providedClass")));

but getting the same exception.

I will appreciate any suggestion.

Thanks
Krys

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.