glenkpeterson
06/11/2021, 11:12 PM// Error here ---v
fun <T : Slugged & BaseModel> suggestSlug(
tempSlug: String,
clazz: Class<T>,
): String
I want to make sure the class passed to this function implements Slugged
(to be sure it has a .slug
property) and extends the abstract class BaseModel
(to be sure it has an .id
property and is a database @Entity
class - I'm using Ebean).
I found this, which shows the set-theory, but doesn't show the syntax I need (I apologize if I am misunderstanding any of this):
https://kotlinlang.org/spec/type-system.html#intersection-types
Should I just make an abstract SluggedBaseModel
? I'd rather not because abstract vars annotated @Column
need to be initialized and this should be a non-null required constructor parameter for each entity bean that uses it.Zach Klippenstein (he/him) [MOD]
06/11/2021, 11:33 PMCLOVIS
06/11/2021, 11:37 PMfun <T> suggestSlug(
tempSlug: String,
clazz: Class<T>,
): String where T : Slugged, T : BaseModel
https://kotlinlang.org/docs/generics.htmlCLOVIS
06/11/2021, 11:39 PMwhere T : S, T : Q
(but in your case it seems you know them so it should work fine)glenkpeterson
06/11/2021, 11:43 PM|
or &
would be prettier (especially if you could use it in a typealias
), but at least the feature is in the language.glenkpeterson
06/11/2021, 11:57 PM(Class)
and a @SuppressWarnings({"rawtypes", "unchecked"})
but I can live with that.rnett
06/12/2021, 12:33 AMCLOVIS
06/12/2021, 7:53 AM<T : A & B>
Sadly it's not powerful enough for what I want to do with it, hopefully the team with rework on that soon