2014年2月7日星期五

Brother came , helpless to solve


public class SomeThread implements Runnable
{
public void run()
{
System.out.println("sleep...至 not runnable状态");
try
{
Thread.sleep(9999);
}
catch (InterruptedException e)
{
System.out.println("I'm interrupted...");
}
}

public static void main(String[] args)
{
Thread thread = new Thread(new SomeThread());
thread.start();
thread.interrupt();
}
}


main () function in this code :
Thread thread = new Thread (new SomeThread ());
Why someTread This class is not defined yet finished , you can instantiate it?
------ Solution ---------------------------------------- ----
no "definition" finished on the citation does not matter , the key is the time to run the referenced class has been defined over.

here with the C language, you first write a function declaration , then you can use a function definition can be written on the back .

public class SomeThread << equivalent function definition line C , the other code can be directly used SomeThread the symbol with the code which is in what position or not.

------ Solution ------------------------------------ --------
you say that the recursive method not finished defined how it can be called a
------ For reference only - -------------------------------------
class did not have defined referring ?
------ For reference only --------------------------------------- < br> who is with you that there is no fixed definition of finished, this is the definition of an anonymous class
------ For reference only ------------------------------ ---------
same question , defining the mean? Thread class , implements runnable interface can be used
------ For reference only --------------------------- ------------

------ For reference only ---------------------------------- -----
I know you want to ask is how this action occurred in the instance of the body of a class definition .
do not think this is too complicated, ignore the position , do not put yourself go around just fine.
------ For reference only -------------------------------------- -
new SomeThread () has been constructed object. Then passed as a parameter to the function
------ For reference only ------------------------------- --------
variables declared in the storage stack , using the new keyword to create an instance of the heap , but this is an anonymous object is created directly on the heap would be finished , no need to re- stack create , save resources not it
------ For reference only ------------------------------- --------
is a temporary object , the finished thing gc directly recovered
------ For reference only --------------- ------------------------
landlord meant to say it the fifth floor ?
If it is, it seems a dead end , if as you say , so-called ' class declaration finished ', seemingly not so defined , in line with the class declaration , jvm will handle ,
- ---- For reference only ---------------------------------------
anti- Granville Shield encryption, no one has solved , and he tried to decrypt the ways the Internet to no avail. .
------ For reference only -------------------------------------- -
new SomeThread () has new
------ For reference only ------------------ ---------------------
I do not think you understand the operation mechanism of java , after the class finished compiled into bytecode file is . class document , this is what you said defining the class , and when jvm running bytecode files already loaded this . class file class and initialize static variables which something, as if there is a main method on entry procedures execute the statement.
so did not know you did not understand

没有评论:

发表评论