3

I have a room database with a entity with some subclass.

Each subclass, has some methods overrides and I need get that overrided methods when I use the entities.

Any way to get all entities and each as correct subclass implementations?

Example:

base class -> Person

sublcass1 -> Teacher

sublcass2 -> Student

And when get all persons, any each is a diferents class (some are Student, some are Teacher...)

var persons = getAllPersons();

if (person[0] as Student)

....

if (person[1] as Teacher)

...

MiguelAngel_LV
  • 1,200
  • 5
  • 16
  • https://stackoverflow.com/questions/7526817/use-of-instance-of-in-java – Tim Sep 13 '18 at 07:29
  • 1
    Sorry. The cuestion is not how use "instance of" in jave or "is" in kotlin. The question is how to get that room create instance of subclass instead of instance of base class – MiguelAngel_LV Sep 13 '18 at 07:32
  • I don't see what else the question would be, can you please clarify – Tim Sep 13 '18 at 07:33
  • If a save a Student class instance, when room return it, it return as Person instance, not as Student instance. – MiguelAngel_LV Sep 13 '18 at 07:35

0 Answers0