Published objects:
import com.example.annoations.NotThreadSafe; import lombok.extern.slf4j.Slf4j; import java.util.Arrays; @Slf4j @NotThreadSafe public class UnsafePublish { private String[] states={"a","b","c"}; public String [] getStates(){ return states; } public static void main(String[] args) { UnsafePublish unsafePublish=new UnsafePublish(); log.info("{}", Arrays.toString(unsafePublish.getStates())); unsafePublish.getStates()[0]="d"; log.info("{}",Arrays.toString(unsafePublish.getStates())); } }
import com.example.annoations.NotRecommend; import com.example.annoations.NotThreadSafe; import lombok.extern.slf4j.Slf4j; @Slf4j @NotThreadSafe @NotRecommend public class Escape { public int thisCanBeEscape=0; public Escape(){ new InnerClass(); } private class InnerClass{ public InnerClass(){ log.info("{}",Escape.this.thisCanBeEscape); } } public static void main(String[] args) { new Escape(); } }