Home > Back-end >  Questions about thread scope inside
Questions about thread scope inside

Time:03-13



Why I have such a piece of code, IP is defined in the new outside the Runnable will be an error (Local variable IP defined in an enclosing scope must be final or effectively final); But the req is not an error?

CodePudding user response:

Rewrite the thread class run method, the inside of the IP scope is IP to the outside of the thread class scope is the main method
The new Runnable () is in a class of data
 class Temp implements Runnable {
Public void the run () {
String IP="";
}
}
  • Related