Sam
08/23/2020, 3:09 PMvar data = false
@Synchronized get
@Synchronized set(value) { field = !value }
fun main() {
println("Value $data")
}
The only way to get bytecode to call getData() is by having this redundant get (which is prompted as redundant getter in IDE)
@Synchronized get() = field
nanodeath
08/23/2020, 3:20 PMnanodeath
08/23/2020, 3:21 PMpublic final static synchronized getData()Z
L0
LINENUMBER 1 L0
GETSTATIC SyncKt.data : Z
IRETURN
L1
MAXSTACK = 1
MAXLOCALS = 0
Sam
08/23/2020, 3:21 PMnanodeath
08/23/2020, 3:22 PMGETSTATIC SyncKt.data : Z
this? .....yeah, that seems to corroborate thatSam
08/23/2020, 3:22 PMprivate static boolean data;
public static final synchronized boolean getData() {
return data;
}
public static final synchronized void setData(boolean value) {
data = !value;
}
public static final void main() {
String var0 = "Value " + data;
System.out.println(var0);
}
nanodeath
08/23/2020, 3:23 PMnanodeath
08/23/2020, 3:23 PMnanodeath
08/23/2020, 3:24 PMSam
08/23/2020, 3:25 PMnanodeath
08/23/2020, 3:27 PMSam
08/23/2020, 3:27 PMnanodeath
08/23/2020, 3:31 PMSam
08/23/2020, 3:31 PMnanodeath
08/23/2020, 3:33 PMSam
08/23/2020, 3:33 PMaraqnid
08/23/2020, 3:59 PMfield = !value
? That sounds like a recipe for confusion.nanodeath
08/23/2020, 4:07 PMSam
08/23/2020, 5:41 PMSam
08/23/2020, 5:51 PMaraqnid
08/23/2020, 7:29 PMprivate var privateData = false
get() = synchronized(this) { field }
set(value) { synchronized(this) { field = value } }
With some added fun if you want this for a top-level property (maybe lock some class object similar to what static synchronized
in Java does)
Or even just create a delegate for applying synchronization a la private var privateData by synchronizeOn(this) { false }
araqnid
08/23/2020, 7:30 PM@Synchronized
annotation is ignored here seems wrongSam
08/23/2020, 7:30 PMKroppeb
08/24/2020, 6:09 AM@Syncronised
supposed to do hereKroppeb
08/24/2020, 6:11 AMnanodeath
08/24/2020, 4:29 PMKroppeb
08/24/2020, 4:45 PMnanodeath
08/24/2020, 4:46 PMKroppeb
08/24/2020, 4:51 PMnanodeath
08/24/2020, 4:57 PMnanodeath
08/24/2020, 4:58 PM