Determining subclass out of a lot of subclasses Java?

You can use tree.getClass().newInstance() In case you want to have some more complex logic than instantiation, you would either need the instanceof approach, or better - make each RBTree subclass have a method that performs that logic (and make that method abstract in RBTree ).

You can use tree.getClass().newInstance(). In case you want to have some more complex logic than instantiation, you would either need the instanceof approach, or better - make each RBTree subclass have a method that performs that logic (and make that method abstract in RBTree).

Very easy and simple. Thanks aswell for mentioning the alternative approach. – Aerus Nov 14 at 13:17.

Using reflection, you can: string name = tree.getClass().getName() Class. ForName(name).newInstance(); Problem is that if the actual implementations have different methods etc. You won't be able to access them.

– Bozho Nov 14 at 13:03 In this case it isn't really necessary, but it does provide an alternative to the other answers, which might be handy. I don't know the rest of his code and maybe he likes passing the classname around better than what he's currently doing.It might get hem thinking. That's all.

– Pieter Nov 14 at 13:06 classnames should not be passed unless you are going through external systems. The class within the JVM is represented by a Class object – Bozho Nov 14 at 13:11.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions