question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to suppress warnings on Assisted annotations used in factory interfaces

See original GitHub issue

Since the latest version 2.32 something like the following code isn’t possible to use anymore because of the change that the type and identifier combo must be unique:

interface FoobarFactory<T : ViewModel> {
    fun create(environmentId: String, wizardId: String, stepId: String): T
}

// there are multiple of such viewmodels that all use those three assisted string parameters,
// which is why FoobarFactory exists.
class FooViewModel @AssistedInject constructor(
    @Assisted environmentId: String,
    @Assisted wizardId: String,
    @Assisted stepId: String
) : ... {
    @AssistedFactory
    interface Factory : FoobarFactory<FooViewModel>
}

I did try several ways to make this code compatible with 2.32 by e.g. changing @Assisted in the viewmodel to @Assisted("parametername") and also adding @Assisted("parametername") to the ‘template’ interface (FoobarFactory) but essentially just this worked (in addition to adding the qualifier to the viewmodel argument of course):

class FooViewModel ... {
    @AssistedFactory
    interface Factory : FoobarFactory<FooViewModel> {
        override fun create(
            @Assisted("environmentId") environmentId: String,
            @Assisted("wizardId") wizardId: String,
            @Assisted("stepId") stepId: String
        ): FooViewModel
    }
}

As I have multiple of these FooViewModel factories I’d prefer to not have to duplicate and override the function several times.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
z3ntucommented, Feb 11, 2021

So this didn’t work:

// plain interface, no @AssistedFactory
interface FoobarFactory<T : ViewModel> {
    fun create(@Assisted("environmentId") environmentId: String, @Assisted("wizardId") wizardId: String, @Assisted("stepId") stepId: String): T
}

and then inheriting from that interface like this without declaring the function there

    @AssistedFactory
    interface Factory : FoobarFactory<FooViewModel>
0reactions
z3ntucommented, Feb 12, 2021

Should be fine. It’s quite a niche use case that I have, so explicitly saying “yes I want to really do this” is probably a nice option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The @SuppressWarnings Annotation in Java - GeeksforGeeks
The @SuppressWarnings Annotation in Java ; hiding, It suppresses warnings relative to locals that hide variable ; serial, It makes the compiler ...
Read more >
SuppressWarnings - Android Developers
For example, if you annotate a class to suppress one warning and annotate a method to suppress another, both warnings will be suppressed...
Read more >
Spring Security without the WebSecurityConfigurerAdapter
Configuring HttpSecurity. In Spring Security 5.4 we introduced the ability to configure HttpSecurity by creating a SecurityFilterChain bean.
Read more >
Java @SuppressWarnings annotation examples - CodeJava.net
The @SuppressWarnings annotation type allows Java programmers to disable compilation warnings for a certain part of a program (type, field, ...
Read more >
JUnit 5 User Guide
The default orderer will be used for all tests unless the @TestMethodOrder annotation is present on an enclosing test class or test interface....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found