是可能的嗎? 我有一個類Listener,可以通過很多其他類實例化,所以在Listener裏面我會知道誰是「父親」;知道誰在誰已經實例化本身就是一個類的實例知道自己
我不想使用
if(objectA instanceOf Class)
....
,但我認爲是這樣的:
if(this.instanceOf Class1)
System.out.println("Hello i'm the class Listener instanced by Class1);
else if(this.instanceOf Class2)
System.out.println("Hello i'm the class Listener instanced by Class2);
這是可能的還是我白癡? ;) 感謝 尼古拉
你能解釋一下你的一類「實例化本身」是什麼意思? –
這是你的意思:http://stackoverflow.com/questions/1483075/find-out-instantiating-object-in-the-constructor-of-a-class –
對不起,誰實例化它 – Nicola