Objects don't have names, unless you happen to be using a class which allows each object to be given one (e.g. via a variable retrieved with getName()
).
In particular, the name of any particular variable used to refer to an object is completely unknown to the object itself. So you can't do:
Object foo = new Object();
// There's no support for this
String name = foo.getName(); // expecting to get "foo"
(Bear in mind that several variables could all refer to the same object, and there don't have to be any named variables referring to an object.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…