M
M
medovuk2018-05-08 01:49:24
Java
medovuk, 2018-05-08 01:49:24

What does t == this mean in code?

I don't understand how to understand the code t == this. creatorThread variable of type Thread. This class extends Thread.

Thread t = Thread.currentThread();
if ( t == creatorThread ) {
    System.out.println(“Creator thread”);
} else if ( t == this ) {
    System.out.println(“New thread”);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dimkss, 2018-05-11
@medovuk

Thread t = Thread.currentThread();
if ( t == creatorThread ) {
System.out.println("Creator thread");
} else if ( t == this ) {
System.out.println("new thread");
}
In general, the code is... elegant, but complicated. (purely my opinion)

E
Eugene, 2018-05-08
@zolt85

This is a comparison of the references of two objects. Those. if the current object and t are equivalent by reference, then the expression will be true.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question