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

Beans of generic interfaces with nested Kotlin type parameters are not found #25201

Closed
helmbold opened this issue Jun 7, 2020 · 3 comments
Closed
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: kotlin An issue related to Kotlin support

Comments

@helmbold
Copy link

helmbold commented Jun 7, 2020

Interface implementations that use nested type parameters with Kotlin types are not found as implementations. The following example fails:

package com.example.demo

import org.springframework.stereotype.Component

interface MyInterface<T> {
    fun doit(): T
}

@Component
class MyImplementation1 : MyInterface<Sequence<Int>> {
    override fun doit(): Sequence<Int> {
        TODO("not implemented")
    }
}

@Component
class MyConsumer(private val my: MyInterface<Sequence<Int>>)

The error message is:

Parameter 0 of constructor in com.example.demo.MyConsumer required a bean of type 'com.example.demo.MyInterface' that could not be found.

But if I use the (similar) Java interface Stream everything is fine:

package com.example.demo

import org.springframework.stereotype.Component
import java.util.stream.Stream

interface MyInterface<T> {
    fun doit(): T
}

@Component
class MyImplementation1 : MyInterface<Stream<Int>> {
    override fun doit(): Stream<Int> {
        TODO("not implemented")
    }
}

@Component
class MyConsumer(private val my: MyInterface<Stream<Int>>)

The application file is identical in both cases:

package com.example.demo

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
    runApplication<DemoApplication>(*args)
}

Possibly related to #22313

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 7, 2020
@encircled
Copy link
Contributor

Hi,

Yes, this is the same issue as #22313, Kotlin Sequence class has out variance, which causes the problem.

@hpy1994-java
Copy link

oops~

@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 11, 2021
@sdeleuze sdeleuze added the theme: kotlin An issue related to Kotlin support label Jan 19, 2022
@sdeleuze
Copy link
Contributor

sdeleuze commented Feb 8, 2023

I close this issue since that's a duplicate of #22313 indeed.

@sdeleuze sdeleuze closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2023
@sdeleuze sdeleuze added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue theme: kotlin An issue related to Kotlin support
Projects
None yet
Development

No branches or pull requests

6 participants