Redundant cast in generated component
See original GitHub issueI have a redundant cast in one of my generated component implementations:
this.provideFooProvider = DoubleCheck.provider((Provider) provideRealFooProvider);
where Foo is an interface and RealFoo is the concrete type.
@Module public abstract class FooModule {
@AppScope @Provides static RealFoo provideRealFoo() {
return Foo.create();
}
@AppScope @Binds abstract Foo provideFoo(RealFoo realFoo);
}
This is such a minor thing, and it doesn’t end up in the bytecode. Totally close this if it’s uninteresting.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
Java redundant casts required in generic method
I was looking at a way to optimize some things in our code base with generic functions. There is a function with return...
Read more >Java static code analysis: Redundant casts should not be used
Redundant casts should not be used ... Unnecessary casting expressions make the code harder to read and understand. Noncompliant Code Example. public void...
Read more >"Redundant cast" warning in generated java code when using ...
There are some "redundant cast" warnings in generated java code when the message type has a one_of field: The message: message Type {...
Read more >Code Inspection: Redundant cast - ReSharper - JetBrains
According to C# documentation, explicit conversion (cast) is redundant in the following cases: Conversions from derived classes to base classes.
Read more >[JDK-8054492] Casting can result in redundant null checks in ...
I talked with Paul and he is asking to not generate uncommon trap for null check in Class.cast() in all cases - just...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ronshapiro @gk5885 I just ran into this while upgrading from 2.16 to 2.23.2. If you’re not going to go with
? extends
would it make sense to at least@SuppressWarnings("cast")
on that method so we can use-Werror
on our codebases?By the way, if someone find this issue, the TL;DR workaround is to open up the visibility of the implementation (so that the generated component can access it):
Exact error message that lead me here for SEO:
Yes, my component is in a different package, and those are my fields.
Oh, that makes sense. Thank you for the fantastic explanation! I appreciate it! I was super curious about the cause. 🌟