What is the proper way to load SubType's into ArrayList of type of BaseType with sqlite select?

61
June 19, 2017, at 02:33 AM

I have a table of BaseType which have the column Type for SubType objects.

In the method that returns ArrayList I select all objects from the BaseType table and want to assign corresponding type to each object.

What is the proper way to do it?

At this point, I have two options in mind:

1, Using reflection which is more expensive.

    BaseType baseType = cast(Class.forName("Type1").newInstance());

And casting it to corresponding SubType using method call

private <T> T cast(Object o)
{
    return (T)o;
}

2, Casting using hardcoded values. Downside - more code, hardcoded values, but much faster.

private BaseType convertStringToSubtype(String objectName)   {
                BaseType baseType;
                if (equals(objectName, "Type1")){
                    baseType = new Type1();
                }
        // else if ... and so on
    }
READ ALSO
who is responsible for offset maintenance?

who is responsible for offset maintenance?

Here are the Kafka docs for public ConsumerRecords<K,V> poll(long timeout)

88
Saving and Reading an ArrayList

Saving and Reading an ArrayList

Saving method(save list is an Arraylist)-

67
Show confirm dialog in Flux architecture

Show confirm dialog in Flux architecture

I'm trying to understand Flux architectureI'm using JavaFX and the FluxFX experimental framework

66
How to Compare a String with a Char

How to Compare a String with a Char

Guys how do i compare a String with a char ? heres my code :

63