can Someone explain to be what this compiler error...
# getting-started
c
can Someone explain to be what this compiler error is telling me and how to fix it?
Copy code
interface AclClassRepository : PagingAndSortingRepository<AclClass, Long>
Copy code
@Component
    class SecurityConfiguration(private val classRepo: AclClassRepository) : WebSecurityConfigurerAdapter() {

        @PostConstruct
        private fun init() {
            val context = SecurityContextHolder.getContext()
            context.authentication = UsernamePasswordAuthenticationToken("system", "system",
                    createAuthorityList("ROLE_ADMIN"))


            val all = classRepo.findAll()
            val reflections = Reflections(this.javaClass.`package`.name)

            val entities = all - reflections.getTypesAnnotatedWith(Entity::class.java)

           // Error:(64, 42) Kotlin: Type parameter bound for S in fun <S : AclClass!> save(p0: S): S
 is not satisfied: inferred type Any! is not a subtype of AclClass!

            entities.forEach { classRepo.save(it) }

//Error:(65, 23) Kotlin: Type parameter bound for S in fun <S : AclClass!> saveAll(p0: (Mutable)Iterable<S!>): (Mutable)Iterable<S!>
 is not satisfied: inferred type Any! is not a subtype of AclClass!

            classRepo.saveAll(entities)


            SecurityContextHolder.clearContext()

        }
}
m
It’s hard to know without knowing the type of
classRepo.findAll()
but it looks like
entities
is a set of
Class
instances (I inferred this only because of the reflection). In that case, it seems that there is no way that elements of
entities
can be of a subtype of
AclClass
like apparently the type bound requires
r
Yep, seems like
classRepo
contains objects of type
AclClass
, and
reflections.getTypesAnnotatedWith(...)
returns
Set<Class<*>>
. You have to have a way of casting your `Class<*>`es to `AclClass`es.