1

Is it possible in java to obtain ConcreetClass.class from interface reference ISomeInterface. I would like to avoid 'instance of' keyword.
On other words, is there:

ISomeInterface intRef = new ConcreetClass();
Class realization = intRef.getRealizationClass();
realization == ConcreetClass.class; // true 

If java doesn't support this operation. Could you recommend me a way to deal with it?

Rudziankoŭ
  • 9,663
  • 16
  • 80
  • 173
  • Possible duplicate of [How can I get a list of all the implementations of an interface programmatically in Java?](http://stackoverflow.com/questions/347248/how-can-i-get-a-list-of-all-the-implementations-of-an-interface-programmatically) – eugenioy Oct 22 '15 at 13:09

2 Answers2

1

You should be able to get the specific class of any object using the getClass() method.

Danail Alexiev
  • 7,234
  • 3
  • 18
  • 27
1

getClass returns the class of the instance.

Class<? extends ISomeInterface> realization = intRef.getClass();
System.out.println(ConcreetClass.class.equals(realization)); //true
Sleiman Jneidi
  • 22,151
  • 12
  • 53
  • 74