@couchbaseuser024 exactly what @ingenthr said.
When you “get” a document, the CAS value is automatically populated. When you then use the replace() operation the CAS will be taken into account and if the optimistic locking fails, you’ll see a CASMismatchException/error depending if you are on the async or sync APIs.