0

I have some object with hierarchy based on BaseSample abstract class BaseSample; class Sample extends BaseSample Then I create one. Sample object = new Sample And then I need to create some method to find previously created object. BaseSample findObjectByString(String objectSampleClassName) It is possible to find already created object by his class name and do not create own list of BaseSample objects? Thanks for reply.

Dima
  • 71
  • 1
  • 5
  • how is your hierarchy defined? does `Sample` class contain more `Sample` objects? – Courage May 14 '17 at 05:44
  • You will usually prefer to create your own list. Everything else would get unreasonably tricky. – Ole V.V. May 14 '17 at 06:48
  • See also [Is there a simple way of obtaining all object instances of a specific class in Java](http://stackoverflow.com/questions/1947122/is-there-a-simple-way-of-obtaining-all-object-instances-of-a-specific-class-in-j). – Ole V.V. May 14 '17 at 06:52
  • What does the string you search by represent? Why not just keep a `Map` and keep instances there? – kaqqao May 18 '17 at 11:40

0 Answers0