0
What does "new Loader()" in " Thread t = new Thread(new Loader()); " means from the below code?
class Loader implements Runnable { public void run() { System.out.println("Hello"); } } class MyClass { public static void main(String[ ] args) { Thread t = new Thread(new Loader()); t.start(); } } is " new Loader() " a new instance of Loader class without name?
3 Respuestas
+ 2
Yes, just a shorter way of writing
Loader load = new Loader();
Thread t = new Thread(load);
t.start();
An even shorter way would be -
new Thread(new Loader()).start();
+ 1
zemiak I agree. Lambdas are pretty cool.
0
or
new Thread( ()->
System.out.println("Hello")
).start();