Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kotlin未型变的类经过android studio make project后会变成形变的类 #1638

Closed
longqingzhao opened this issue Oct 22, 2019 · 2 comments

Comments

@longqingzhao
Copy link

我写了一个kt类如下:
class ViewModelProviderFactory @Inject
constructor(private val creators: Map<Class, Provider>) :
ViewModelProvider.Factory {

override fun <T : ViewModel> create(modelClass: Class<T>) =
    (creators[modelClass]
        ?: creators.filterKeys { it.isAssignableFrom(modelClass) }.values.first()).get() as T

}
然后我点击android studio->build->make project后生成的java类如下:

public final class ViewModelProviderFactory_Factory implements Factory<ViewModelProviderFactory> {
  private final Provider<Map<Class<? extends ViewModel>, ? extends Provider<ViewModel>>>
      creatorsProvider;

  public ViewModelProviderFactory_Factory(
      Provider<Map<Class<? extends ViewModel>, ? extends Provider<ViewModel>>> creatorsProvider) {
    this.creatorsProvider = creatorsProvider;
  }

  @Override
  public ViewModelProviderFactory get() {
    return new ViewModelProviderFactory(creatorsProvider.get());
  }

  public static ViewModelProviderFactory_Factory create(
      Provider<Map<Class<? extends ViewModel>, ? extends Provider<ViewModel>>> creatorsProvider) {
    return new ViewModelProviderFactory_Factory(creatorsProvider);
  }

  public static ViewModelProviderFactory newInstance(
      Map<Class<? extends ViewModel>, ? extends Provider<ViewModel>> creators) {
    return new ViewModelProviderFactory(creators);
  }
}

以上出现了一个问题:我并没有让Provider进行任何型变操作,生成的java类意外地出现了? extexds.我想这是一个bug!因为当我试着用java写这段代码时并没生成? extends而且代码运行正常.所以这是一个bug!

@tbroyer
Copy link

tbroyer commented Oct 22, 2019

You need to use @JvmSuppressWildcard; see #900 (comment)

@longqingzhao
Copy link
Author

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants