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ŭ
  • 10,681
  • 20
  • 92
  • 192
  • 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,624
  • 3
  • 20
  • 28
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,907
  • 14
  • 56
  • 77