phongvan phongvan - 4 months ago 11
Android Question

How to get direct class name of instance?

I have supper

class A
and many child class name
A1
,
A2
, ...

I make a function use with
A
and all child class of
A
:

public void MyFunction(A Ainstance, ....)


In this function I need get direct name of instance
Ainstance
(may be A, A1, A2 ... ). I don't want use
instance of
function because I don't want modify this function when I create more child class of A.

Answer

You can use reflection and the class object. Ainstance.getClass().getName();