On the other hand, some synchronized methods could be marked as pure, because the purpose of synchronization here is to keep the collection internal integrity rather than to wait for an event in another thread. If its return value is not used, removing its invocation will not affect program state or change the semantics, unless the method call throws an exception (exception is not considered to be a side effect).Ī method should not be marked as pure if it does not produce a side effect by itself, but it could be used to establish the happens-before relation between an event in another thread, so that changes performed in another thread might become visible in current thread after invocation of this method. The pure attribute is intended for methods that do not change the state of their objects, but just return a new value. The value attribute contains clauses describing causal relationship between arguments and the returned value. The annotation has two attributes - value and pure. You can use this annotation not only for annotating your own code but also for other existing libraries. This lets the IDE find problems in methods which call methods that you have annotated. Annotation is used for defining a contract that a method must meet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |