phongvan phongvan - 1 year ago 72
Android Question

How to get direct class name of instance?

I have supper

class A
and many child class name
, ...

I make a function use with
and all child class of

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

In this function I need get direct name of instance
(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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download