I'll just quote two paragraphs from docs
first
A field may be declared volatile, in which case the Java Memory Model
ensures that all threads see a consistent value for the variable
(§17.4).
second
The memory model describes possible behaviors of a program. An
implementation is free to produce any code it likes, as long as all
resulting executions of a program produce a result that can be
predicted by the memory model.
This provides a great deal of freedom for the implementor to perform a myriad of code transformations, including the reordering of actions
and removal of unnecessary synchronization.
Now If you will refer to most of the tutorials regarding votatile keyword in java
, most of them will suggest the same thing as you suggested, i.e., The value of this variable will never be cached thread-locally: all reads and writes will go straight to "main memory".
But docs make no guarantee about it. Although it never denies it as well. It just says this is the possbile behaviour.
So I would say that your teacher is correct. According to docs (and not the most tutorials other than docs), Volatile keyword definitely does not promise that the value of the variable will be saved in the main memory.
However, this doesn't makes you wrong, it all depends upon the JVM implementation.