Reputation: 445
public static void test(int x, int y) {
Thread thread = new Thread() {
@Override
public void run() {
System.out.println(x);
}
};
thread.start();
}
This is my code. I can't get value of x. How do I get the value of the parameter x in the method of the anonymous class of the function?
Upvotes: 0
Views: 155
Reputation: 6277
Declare parameter x
final
public static void test(final int x, int y) {
Thread thread = new Thread() {
@Override
public void run() {
System.out.println(x);
}
};
thread.start();
}
Upvotes: 7