Your expression parses as (new T3()).test()
, not new (T3().test())
as if it were destined to create a new object. Therefore, as mentioned in comments, it creates a T3
object, invokes the test()
method on it, and discards the result. (The T3
object may or may not survive this processs, since it could publish pointers to itself in its constructor or in test()
.) It's no different from writing
static T3 findSomeT3() { /* could return a new one or an existing one */ }
public static void main(String[] args) {
findSomeT3().test();
}
which also might or might not discard a T3
object upon completion.
Note, by the way, that the name after new
should not be considered a constructor; it's a class name. A constructor is invoked to initialize it, of course, and the constructor is declared by treating the class's name as a function name, but it's still the class you're talking about.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…