Equivalent of C# lock in Java?
For example:
public int Next() {
lock (this) {
return NextUnsynchronized();
}
}
How do I port this C# method to Java?
The closest thing you can get is a struct .
Parameters in C functions There are two ways to pass parameters in C: Pass by Value, Pass by Reference.
1. C Classes. A class consists of an instance type and a class object: An instance type is a struct containing variable members called instance variables and function members called instance methods.
The main type of templates that can be implemented in C are static templates. Static templates are created at compile time and do not perform runtime checks on sizes, because they shift that responsibility to the compiler.
public int Next() {
synchronized (this) {
return NextUnsynchronized();
}
}
That's it. And the next code is better.
public synchronized int Next() {
return NextUnsynchronized();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With