Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Kotlin: enumeration and class reflection

Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have the following enum:

Each of the class (e.g. ClassOne) is a data class implementing interface MyClass<Entity> as follows:

My issue is that I have a method taking each of the mapped classes as an argument and I am trying to find a way to make it more generic by getting the corresponding class per enum. I have written the following:

which correctly returns the mapped class, however i am struggling to correctly using it here:

Essentially I want to avoid replicating the method signature by not having to pass in the concrete mappedClass as a parameter. The issue is that the returns , while the savedEvent is expecting the concrete data class . I have attempted at casting it to MyClass to Entity, but with no luck. Can you help? As it stands, I now have 3 identical methods whose only difference is the abovementioned argument/parameter.

Thank you for your help

You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic